From:             php at prog dot hu
Operating system: 
PHP version:      5.3.0RC1
PHP Bug Type:     Feature/Change Request
Bug description:  Provide a way to serialize classes to include files

Description:
------------
This entry is about a feature request for a way to serialize/export
complete class structures to include files. 

The purpose of this extensions would be to enable template systems,
configuration intensive frameworks, etc. to use a persistent object storage
which can take advantage of present opcode accelerators (eAccelerator,
mmcache, etc), and thus avoid the overhead of classical parsing of
serialized objects.

Classical serialize()/unserialize() gets very slow when the serialized
state grows large (>100KB), and is also a waste of CPU with mostly static
serialized objects, as it forces PHP to parse the serialized string over
and over (even when it's more effective than direct PHP source parsing).
The solution to this problem could be to provide a way to export complete
objects and object structures (also including circular or back+forth
references) to PHP include files, which then in turn - when stored in the
file system - could be easily re-instantiated at any point without the need
of a re-parse if an accelerator is present in the system. (Even if an
accelerator isn't present, the overhead of parsing a var_export-style
object-construction shouldn't be lot worser than parsing the output of
serialize(), and shouldn't result in significantly larger output).

Currently PHP provides no integral means to to such an export
(var_export() fails on circular references and too deep object nesting),
and even though this can be circumvented from custom PHP code (with a lot
of tricks, like casting an object to an array to be able to enumerate all
it's members, including hidden ones, and usage of reflection API to get the
actual value of hidden member fields), there's practically no way to
re-instantiate the class in/from the generated source (include), as the
standard constructor can't be avoided/circumvented when re-instantiating an
object, making it impossible to load an object state directly back into
memory.

To solve the problem PHP should provide a way to statically instantiate a
class with predefined member field values (much like the __set_state()
magic method, but _without the need of define this method in each classes_,
and also without the method calling the "normal" constructor used for
in-code instantiation, which defeats the purpose of serialization). This
method the could be used in the generated include files to re-instantiate
the class and restore it's state as it was when it was serialized. Circular
references can be easily resolved with late-binding in the include, so
practically the var_export() style can be preserved (with extra fixup code
added after the basic construction of the object-hierarchy skeleton, to
resolve the circular references). 

The extra method wouldn't open up any new security vulnerabilities and
affect the object integrity (by avoiding the standard constructor and thus
theorethically enabling to set all kind of inconsistent values in member
fields accross the objects), as the input of unserialize() can be
manipulated too anyway, so construction of possibly invalid object states
and creation of objects with arbitrary member field values is already
possible even without this special method/function I'm asking for.


-- 
Edit bug report at http://bugs.php.net/?id=48079&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48079&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48079&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48079&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48079&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48079&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48079&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48079&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48079&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48079&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48079&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48079&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48079&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48079&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48079&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48079&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48079&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48079&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48079&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48079&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48079&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48079&r=mysqlcfg

Reply via email to