php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30324 serialize() should work on internal classes
Submitted: 2004-10-04 17:00 UTC Modified: 2012-09-23 16:40 UTC
From: matthias dot hoseit at comline dot de Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.0.* OS: *
Private report: No CVE-ID: None
 [2004-10-04 17:00 UTC] matthias dot hoseit at comline dot de
Description:
------------
The function serialize() should work on internal classes like DOMDocument. I my opinion this could be a nice Feature.

Best Regards Matthias Hoseit


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-04 19:40 UTC] helly@php.net
serialize() works on internal classes. It doesn't work on virtual properties and this problem usually occurs with internal classes.

What you want is more control over serialization. Eventually the solution is a set of new magic callbacks 
function /* string */ __serialize()
static function /* instance */ __unserialize(string $data)

__serialze() would need to return the string used to recreate the instance and __unserialize() would recreate it from the passed string. We could also make __unserialize() a non static fucntion in which case the instance would be created prior to calling the function. However the static functionality allows much more flexibility. 

For example the static functionality allows instance creation through factory methods and they could store the information needed to reread a xml document or reopen a database connection.

 [2012-09-23 16:40 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2012-09-23 16:40 UTC] nikic@php.net
Closing as serialization for internal classes is already supported if the class implements it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC