# severe serialize problem

- Thread: https://externals.io/message/1866
- Original archive: https://news-web.php.net/php.internals/1866
- Started by Dmitriy Myshkin on 2003-05-21T19:46:17+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1866 — Dmitriy Myshkin — 2003-05-21T19:46:17+00:00

URL: https://externals.io/message/1866#1866

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.

---

## #1914 — Timm Friebe — 2003-05-22T21:44:00+00:00

URL: https://externals.io/message/1866#1914 · In reply to: #1866

> 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

---

## #1915 — Timm Friebe — 2003-05-22T22:20:26+00:00

URL: https://externals.io/message/1866#1915 · In reply to: #1914

[...]
> 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

---

## #1918 — Timm Friebe — 2003-05-22T22:58:54+00:00

URL: https://externals.io/message/1866#1918 · In reply to: #1915

> 
> [...]
> > […]
> 
> 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

---

## #1920 — Timm Friebe — 2003-05-22T23:07:13+00:00

URL: https://externals.io/message/1866#1920 · In reply to: #1918

> 
> > […]
> 
> 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
