News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sebastian Bergmann's Blog:
Freezing and Thawing PHP Objects
December 01, 2008 @ 11:12:18

Sebastian Bergmann has posted details (and a patch) for freezing and unfreezing objects via the new setAccessible method included in the SPL in PHP 5.3.

One of the many new features that have been added for PHP 5.3 is the setAccessible() method of the ReflectionProperty class that is part of PHP's Reflection API. This method makes protected and private attributes (unfortunately, the class is called ReflectionProperty instead of ReflectionAttribute) of a class or object accessible for the ReflectionProperty::getValue() and ReflectionProperty::setValue() methods, thus making protected and private attributes "open" for full read and write access from the outside.

A bit of code shows how to "freeze" and "thaw" the objects out - creating an object, calling the freeze() method on it to protect it from use, then the thaw() method to bring it back out where it can be accessed. Stefan Priebsch helped to create this class and the patch.

0 comments voice your opinion now!
freeze thaw object php5 patch spl setaccessible


blog comments powered by Disqus

Similar Posts

Matthew Turland's Blog: New SPL Features in PHP 5.3

David Goodwin's Blog: Book Review: Object-Orientated Programming with PHP5 (Hasin Hayder, Packt)

Mike Lively's Blog: Late static binding....sorta :/

Rob Thompson's Blog: PHP and Solaris - getcwd() Behavior

Nefarious Designs: Object-Oriented PHP Part 4: PHP5's Improved Features


Community Events





Don't see your event here?
Let us know!


release symfony application configure unittest series introduction language library api threedevsandamaybe code podcast list wordpress install laravel community interview developer

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework