ZE2 race condition

php.internals

Jan Schneider

23 years ago
Running the following code: class Foo { var $bar_ref; } class Bar { var $foo_ref; } $foo = new Foo(); $bar = new Bar(); $foo->bar_ref = $bar; $bar->foo_ref = $foo; var_dump($foo); var_dump($bar); $s = serialize($foo); var_dump($s); $s = serialize($bar); var_dump($s); in PHP_4_3 results to: object(foo)(1) { ["bar_ref"]=> object(bar)(1) { ["foo_ref"]=> NULL } } object(bar)(1) { ["foo_ref"]=> object(foo)(1) { ["bar_ref"]=> object(bar)(1) { ["foo_ref"]=> NULL } } } string(58) "O:3:"foo":1:{s:7:"bar_ref";O:3:"bar":1:{s:7:"foo_ref";N;}}" string(86) "O:3:"bar":1:{s:7:"foo_ref";O:3:"foo":1:{s:7:"bar_ref";O:3:"bar":1:{s:7:"foo_ref";N;}}}" in HEAD: object(foo)#1 (1) { ["bar_ref"]=> object(bar)#2 (1) { ["foo_ref"]=> object(foo)#1 (1) { ["bar_ref"]=> object(bar)#2 (1) { ["foo_ref"]=> *RECURSION* } } } } object(bar)#2 (1) { ["foo_ref"]=> object(foo)#1 (1) { ["bar_ref"]=> object(bar)#2 (1) { ["foo_ref"]=> object(foo)#1 (1) { ["bar_ref"]=> *RECURSION* } } } } and a segfault (apache 1 sapi) or a runaway process (cli sapi). Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - discover your knowledge http://www.tip4all.de - Deine private Tippgemeinschaft

Zeev Suraski

23 years ago
That's quite intentional - assignments in ZE2 are handle based, versus the value based in ZE1. That's more or less the biggest change in ZE2 :) If you want to create copies like in ZE1 you can use __clone(). Zeev At 06:13 25/03/2003, Jan Schneider wrote:

Jan Schneider

23 years ago
Quoting Zeev Suraski <zeev@zend.com>:
> That's quite intentional - assignments in ZE2 are handle based, versus > the > value based in ZE1. That's more or less the biggest change in ZE2 :) > > If you want to create copies like in ZE1 you can use __clone().
That's true of course, but serialize() still shouldn't segfault, no?
> At 06:13 25/03/2003, Jan Schneider wrote: > >Running the following code: > > > >class Foo { > > var $bar_ref; > >} > > > >class Bar { > > var $foo_ref; > >} > > > >$foo = new Foo(); > >$bar = new Bar(); > >$foo->bar_ref = $bar; > >$bar->foo_ref = $foo; > > > >var_dump($foo); > >var_dump($bar); > > > >$s = serialize($foo); > >var_dump($s); > >$s = serialize($bar); > >var_dump($s); > > > > > >in PHP_4_3 results to: > > > >object(foo)(1) { > > ["bar_ref"]=> > > object(bar)(1) { > > ["foo_ref"]=> > > NULL > > } > >} > >object(bar)(1) { > > ["foo_ref"]=> > > object(foo)(1) { > > ["bar_ref"]=> > > object(bar)(1) { > > ["foo_ref"]=> > > NULL > > } > > } > >} > >string(58) "O:3:"foo":1:{s:7:"bar_ref";O:3:"bar":1:{s:7:"foo_ref";N;}}" > >string(86) > >"O:3:"bar":1:{s:7:"foo_ref";O:3:"foo":1:{s:7:"bar_ref";O:3:"bar":1:{s:7:"foo_ref";N;}}}" > > > > > >in HEAD: > > > >object(foo)#1 (1) { > > ["bar_ref"]=> > > object(bar)#2 (1) { > > ["foo_ref"]=> > > object(foo)#1 (1) { > > ["bar_ref"]=> > > object(bar)#2 (1) { > > ["foo_ref"]=> > > *RECURSION* > > } > > } > > } > >} > >object(bar)#2 (1) { > > ["foo_ref"]=> > > object(foo)#1 (1) { > > ["bar_ref"]=> > > object(bar)#2 (1) { > > ["foo_ref"]=> > > object(foo)#1 (1) { > > ["bar_ref"]=> > > *RECURSION* > > } > > } > > } > >} > > > >and a segfault (apache 1 sapi) or a runaway process (cli sapi). > > > >Jan. > > > >-- > >http://www.horde.org - The Horde Project > >http://www.ammma.de - discover your knowledge > >http://www.tip4all.de - Deine private Tippgemeinschaft > > > >-- > >PHP Internals - PHP Runtime Development Mailing List > >To unsubscribe, visit: http://www.php.net/unsub.php > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - discover your knowledge http://www.tip4all.de - Deine private Tippgemeinschaft

Zeev Suraski

23 years ago
At 04:56 26/03/2003, Jan Schneider wrote:
>Quoting Zeev Suraski <zeev@zend.com>: > > > That's quite intentional - assignments in ZE2 are handle based, versus > > the > > value based in ZE1. That's more or less the biggest change in ZE2 :) > > > > If you want to create copies like in ZE1 you can use __clone(). > >That's true of course, but serialize() still shouldn't segfault, no?
Of course it's a bad idea for anything to segfault :) It's not ZE2's fault, though... Zeev

Jan Schneider

23 years ago
Quoting Zeev Suraski <zeev@zend.com>:
> At 04:56 26/03/2003, Jan Schneider wrote: > >Quoting Zeev Suraski <zeev@zend.com>: > > > > > That's quite intentional - assignments in ZE2 are handle based, > versus > > > the > > > value based in ZE1. That's more or less the biggest change in ZE2 :) > > > > > > If you want to create copies like in ZE1 you can use __clone(). > > > >That's true of course, but serialize() still shouldn't segfault, no? > > Of course it's a bad idea for anything to segfault :) It's not ZE2's > fault, though...
No, but we know that ZE2 can do it better. Looking at the output of var_dump() it seems that it is able to detect infinite recursion, is there a (technical) reason that the same detection isn't applied to serialize()? Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - discover your knowledge http://www.tip4all.de - Deine private Tippgemeinschaft