Re: defining a global object table
| From: | Johannes Schlüter | Date: | Mon, 07 Nov 2011 21:36:06 +0000 |
| Subject: | Re: defining a global object table | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-8820@lists.php.net to get a copy of this message | ||
Hi,
I didn't think completely through your mail, but I think you want to
look at PHP's serializer, especially php_add_var_hash() and its usage.
On Sun, 2011-11-06 at 17:14 -0800, j adams wrote:
> ZEND_BEGIN_MODULE_GLOBALS(amf)
> zval **objects_and_arrays; // array containing memory addresses of
> arrays and objects encountered
> int objects_and_arrays_count; // number of serialized arrays/objects
> stored in the array
> int objects_and_arrays_allocated; // number of slots allocated for the array
> ZEND_END_MODULE_GLOBALS(amf)
Don't use globals for that. You might have stuff like "nested
serialisation", again using php serialisation as example with a
non-sense but possible example:
<?php
class A implements Serializable {
public $p;
public function serialize() {
return base64_encode(serialize($this->p));
}
public function unserialize($data) {
$this->p = base64_decode(unserialize($data);
}
}
$data = array(new stdclass(), new A());
$data[1]->p = $data[0];
serialize($data);
?>
In this case a second independent serialisation is started while the
first one is still running, the global variable therefore would be
poluted.
Better is to pass the "var_hash" (as it is called in PHP's serializer as
mentioned above) as parameter.
johannes