ID: 48100 Comment by: php at prog dot hu Reported By: php at prog dot hu Status: Open Bug Type: Feature/Change Request PHP Version: 5.3.0RC1 New Comment:
I forgot to mention it, but of course member fields with no default values set forth in the class definition, but an actual value of NULL could be handled the same way (eg. omitted from output) in the "optimized" serialization mode, as member fields default to that value anyway after construction, so unserialize() would still produce the same object from the "full" and "optimized" strings. Previous Comments: ------------------------------------------------------------------------ [2009-04-28 13:51:17] php at prog dot hu Description: ------------ This entry is about a feature request for the extension of the serialize() function, to optinally enable applications to store their persisent objects in a shorter, more efficient way than now. Currently serialize() stores all member fields of the objects in the output string, even if most of those member fields still have their default values as defined in their appropriate class' defintion. This is a waste of storage space and processing power at re-parse time (deserialization). Applications therefore should have the option to tell PHP to store only those member fields in serialized object descriptions, which have non-default values. This could be achieved by adding a second, optional parameter to serialize(), which (if set to true for ex) would invoke this "optimized" behaviour. Reloading (deserialization)of the objects stored in this "optimized" format should occour the same way as now (with a regular unserialize()). The modification I'm proposing has practically no compatibility impacts, as serialize() currently has no second parameter, so old code would still emit full object defintions (with all member fields included, even those with default values), and provide byte-to-byte the same output as in older version. Also unserialization would require no code change, since even in current PHP implementations, if a member field is not included in the string passed to unserialize(), the value of the field in the returned object will default to the value set forth in the class defintion field (if any). That means that the same unserialize() call could take both the old "full" and the new "optimized" strings, and would construct exactly the same object from them, provided the member fields' definitions in the class file wasn't changed in regard to the default values of those field (that's why we need to make the change optional, so applications developers can meet their choice whether they prefer speed/storage space benefits over strict compatibility, especially, that the latter one can be taken care of from application code, too). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48100&edit=1