severe serialize problem

php.internals

Dmitriy Myshkin

23 years ago
an object that is in a namespaced class that is serialized and then deserialized becomes a "__PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name]". It seems serialize/deserialize don't understand namespaces. Namespace app { class berries { public $name; public $quantity; function __construct($name=NULL) { $this->name = $name; } } $object = new app::berries("aberry"); $objecttext = serialize($object); $objectnew = unserialize($objecttext); print_r($objectnew); Best Regards, Dmitriy Myshkin Software Architect T3Link, Inc.

Timm Friebe

23 years ago
On Wed, 2003-05-21 at 21:46, Dmitriy Myshkin wrote:
> an object that is in a namespaced class that is serialized and then > deserialized becomes a "__PHP_Incomplete_Class Object ( > [__PHP_Incomplete_Class_Name]". It seems serialize/deserialize don't > understand namespaces.
These patches to php_incomplete_class.h and var_unserializer.re, though not thoroughly tested, fix this. Test script: <?php namespace Foo:Baz { class Bar { } } class Baz { } $bar= new Foo:Baz::Bar(); var_dump($bar, serialize($bar), unserialize(serialize($bar))); $baz= new Baz(); var_dump(serialize($baz), unserialize(serialize($baz))); ?> You will need re2c to compile, see http://www.tildeslash.org/re2c/ - Timm

Timm Friebe

23 years ago
On Thu, 2003-05-22 at 23:44, Timm Friebe wrote: [...]
> These patches to php_incomplete_class.h and var_unserializer.re, though > not thoroughly tested, fix this.
Here's a patch to php_incomplete_class.h with corrected whitespace. Some lines were indented with spaces instead of tabs... - Timm

Timm Friebe

23 years ago
On Fri, 2003-05-23 at 00:20, Timm Friebe wrote:
> On Thu, 2003-05-22 at 23:44, Timm Friebe wrote: > [...] > > These patches to php_incomplete_class.h and var_unserializer.re, though > > not thoroughly tested, fix this. > > Here's a patch to php_incomplete_class.h with corrected whitespace. Some > lines were indented with spaces instead of tabs...
While I'm at it: This patch also gets rid of memory leaks that occur when using the unserialize_callback_func ini directive. - Timm

Timm Friebe

23 years ago
On Fri, 2003-05-23 at 00:58, Timm Friebe wrote:
> On Fri, 2003-05-23 at 00:20, Timm Friebe wrote: > > On Thu, 2003-05-22 at 23:44, Timm Friebe wrote: > > [...] > > > These patches to php_incomplete_class.h and var_unserializer.re, though > > > not thoroughly tested, fix this. > > > > Here's a patch to php_incomplete_class.h with corrected whitespace. Some > > lines were indented with spaces instead of tabs... > > While I'm at it: This patch also gets rid of memory leaks that occur > when using the unserialize_callback_func ini directive.
And this one gets rid of *all* of them. Sorry for all the spam here:) Test script used: <?php function autoload($fqcn) { list($namespace, $class)= explode('::', $fqcn); if ('power' == $namespace) { eval('namespace '.$namespace.' { class '.$class.' {}}'); } } namespace Foo:Baz { class Bar { } } class Baz { } $bar= new Foo:Baz::Bar(); var_dump($bar, serialize($bar), unserialize(serialize($bar))); $baz= new Baz(); var_dump(serialize($baz), unserialize(serialize($baz))); var_dump(unserialize('O:7:"Binford":0:{}')); ini_set('unserialize_callback_func', 'autoload'); var_dump(unserialize('O:14:"Power::Binford":0:{}')); var_dump(unserialize('O:14:"Idiot::Binford":0:{}')); ?> - Timm

(Marcus Börger)

23 years ago
At 01:07 23.05.2003, Timm Friebe wrote:
>On Fri, 2003-05-23 at 00:58, Timm Friebe wrote: > > While I'm at it: This patch also gets rid of memory leaks that occur > > when using the unserialize_callback_func ini directive. > >And this one gets rid of *all* of them. Sorry for all the spam here:)
Thanks Timm - applied. marcus