PHP Sadness

Segfault during deep recursion

Deep recursion during php clone will cause a segfault:

$ php -r 'class A { public function __clone() { clone $this; } } clone new A();'
Segmentation fault

This can happen during cloning of large or self-referential data structures, such as linked lists. This was filed as a bug in 2009, but marked as "not a bug" because "Infinite recursion crashes. There's no fix for that."

In PHP versions before 5.3, this happens for any deep recursion:

$ php -r 'function a(){ global $i; $i++; print "$i\n"; a(); } a();'

(snip a few thousand lines...)

19162
19163
19164
19165
19166
Segmentation fault