PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of Ninsuo   PHP Public Wrap   readme.txt   Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: Documentation
Class: PHP Public Wrap
Access an object private variables and functions
Author: By
Last change:
Date: 9 years ago
Size: 1,182 bytes
 

Contents

Class file image Download
PublicWrap Set properties and methods visibility to public This class doesn't change behaviour of your original object : it only wraps property and method calls to make them visibles using reflection. This is useful when you're doing unit tests on protected and private methods, or if you want to mock a protected/private dependancy of an object. --- Quick usage sample : class A { private $x = 42; } Normal behaviour : $test = new A(); echo $test->x; // fatal error: $x is private With PublicWrap : $test = new A(); $proxy = new PublicWrap($test); echo $test->x; // 42 See demo for more details (works with private and protected methods and properties). --------- How does it work ? PHP has magic methods: __get($property) let us implement the access of a $property on an object __set($property, $value) let us implement the assignation of a $property on an object __call($method, $args) let us implement a $method call PHP has reflectiion classes: Reflection is a powerful tool that let us access internal constructs of classes in PHP. --------- Changelog 1.0 *** Original version ***