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

Sebastian Bergmann's Blog:
Cool PHP Objects Sleep on the Couch
Jan 12, 2009 @ 18:03:06

This new post from Sebastian Bergmann combines two technologies - the Object_Freezer class and the Couch DB to make a simple object storage system.

The Object_Freezer library for PHP provides the low-level functionality to store ("freeze") and fetch ("thaw") any PHP userland object to and from arbitrary object stores. Today I added an object storage implementation that uses Apache CouchDB as its backend.

His example creates an instance of a Foo class, passes it into the "freezer" object which, thanks to his new additions, automatically drops it into a Couch DB database for holding. The same is done for the "thaw" process - a call to fetch() and the object is returned as good as new.

tagged: object freeze unfreeze couchdb objectfreezer thaw

Link:

Sebastian Bergmann's Blog:
Freezing and Thawing PHP Objects
Dec 01, 2008 @ 17: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.

tagged: freeze thaw object php5 patch spl setaccessible

Link:


Trending Topics: