#38315 [NEW]: Constructing in the destructor causes weird behaviour
From: sean@php.net
Operating system: Linux (N/A)
PHP version: 5.1.4
PHP Bug Type: Scripting Engine problem
Bug description: Constructing in the destructor causes weird behaviour
Description:
------------
Hi,
I already discussed this with Gopal, so he'll probably have something more
enlightening to say about it.
When calling a class' constructor from one of its object's destructors,
the engine behaves strangely.
I expected it to recurse forever and segfault like PHP normally does on
infinite recursion.
Yes, I know I /shouldn't/ be doing this. I just want to make sure
something bad isn't happening internally (and document this behaviour).
S
Reproduce code:
---------------
class Foo {
function __construct() { echo "constructing\n"; }
function __destruct() { $GLOBALS['foo'] = new Foo(); }
}
$foo = new Foo();
Expected result:
----------------
constructing
constructing
... (some large number of times)
constructing
constructing
[[Segmentation Fault]]
Actual result:
--------------
constructing
constructing
constructing
constructing
(yes, only 4 times. 4 is a strange number here, no?)
--
Edit bug report at http://bugs.php.net/?id=38315&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38315&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38315&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38315&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38315&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=38315&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38315&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38315&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38315&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38315&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38315&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=38315&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=38315&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38315&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38315&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38315&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38315&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38315&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38315&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38315&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38315&r=mysqlcfg
Thread (4 messages)
- sean@php.net