#012433: Allow objects to be stored

Description:

Maybe serialize() and unserialize() could be useful to allow storage of objects into a cache like APC (if APC does not support storing objects yet).


Environment:

Operating System:
PHP Version: (please be specific, like '4.4.3' or '5.1.5')
Database and version:
Browser (and version):


- Attachments

No attachments for this issue.


- Comments

APC and Memcache already allow objects to be stored. APC actually stores objects better than it stores arrays. This would only be needed for the file storage methods.

http://us3.php.net/manual/en/function.apc-store.php#70822url

#256128 by Grady Kuhnline on March 25th, 2008 [Permanent Link]

[un]serialize() does not work well with objects, especially with recursive structures. That was the reason for not implementing file storage for objects at all.

#256159 by Tobias Schlitt on March 27th, 2008 [Permanent Link]

using serialize() with file storage also has a huge problem with charsets: serialized data cannot be converted from/to utf8 and the deserialized back. Not a huge problem for mem caches, but if you store stuff in files, it might live longer than expected...

#256983 by Gaetano Giunta on June 7th, 2008 [Permanent Link]

Isn't JSON a better option then php serialization with respect to unicode strings?

#256987 by Paul Borgermans on June 7th, 2008 [Permanent Link]

Well, you do not store string length, so you can utf8encode/decode and be fine with it...

...otoh json is by definition UTF8, so anything else will not qualify.

The json_encode (and decode) php function are pretty fast, being based on a state machine hand-coded in C...

...otoh it is assumed that the php data to be encoded is in utf8 already. If it is not, you have to run it through utf8_encode, and it might slow things down quite a bit

#256988 by Gaetano Giunta on June 7th, 2008 [Permanent Link]

We'll go for using PHPs var_export() to realize this and provide an interface ezcBaseExportable to indicate that objects can be stored. Such objects will then be enabled for being cached in certain file storages.

#257092 by Tobias Schlitt on June 17th, 2008 [Permanent Link]

Besides checking for ezcbaseexportable, I think it would be nice if the serializer also called magic functions sleep and wakeup on the objects it stores.

It makes it easier to serialize recursive objects / objects with resources, and fits in with the overall php way of doing things.

In fact we could even check: if a class has _sleep and/or __wakeup, we can assume it is serializable, without introducing our own interfaces - making it easier to use classes from outside ezc!

#258892 by Gaetano Giunta on November 3rd, 2008 [Permanent Link]

Implemented in rev. #10650.

#262281 by Tobias Schlitt on July 14th, 2009 [Permanent Link]

- History
Properties
Type Enhancement
Priority Medium
Component Components » Cache
Affects 1.3 - Cache 1.3
Fix Version 2009.2 sprint 1 - eZ components 2009.2 sprint 1
Reporter Kristof Coomans
Responsible Tobias Schlitt
Status 0 Closed
Resolution Implemented
Created January 23rd, 2008
Updated July 14th, 2009
Resolved July 14th, 2009
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels