From: Operating system: Ubuntu PHP version: 5.3.10 Package: Class/Object related Bug Type: Bug Bug description:Wrong destructors order
Description: ------------ followed: https://bugs.php.net/bug.php?id=36759 They told that fixed in 5.2*, but its wrong! Reprodused in 5.3.2 Destructors on allocated objects should be called in reverse order: $a = new world(); $b = new human(); == Shold be called as: world->__construct(); human->__construct(); human->__destruct(); world->__destruct(); == Now its calling as: world->__construct(); human->__construct(); world->__destruct(); // now people, cars and other exists without world. wtf?? human->__destruct(); == Why i think current way its wrong: When we creating object $b, we expecting that object $a exists. And while lifetime $b, object $a should be exist. Even $b dying, $a should be exists. We expect in $a that $b may be not exist, but we should`t check in all methods of $b 'is $a exist'. Destructor its not exception and should be executed right. == Some simular reports: https://bugs.php.net/bug.php?id=38572 https://bugs.php.net/bug.php?id=29032 (if we imagine that $SESSION = new bla_bla(), before our code) Test script: --------------- class screen { public $screen; public function __construct() { echo "screen construct<br>"; $text->screen = ""; } public function Write( $text ) { echo "writed to screen $text<br>"; $this->screen .= $text; } public function __destruct() { echo "screen destruct<br>"; echo $this->screen; } } $A = new screen(); class dummy { public function __constuct() { echo "dummy constuct<br>"; } public function __destuct() { echo "dummy destruct<br>"; global $A; $A->Write("Dummy: I`m dying!<br>"); // or $A->DoVeryImportantActionBeforeDie($bla, $bla1); } } $B = new dummy(); Expected result: ---------------- screen construct dummy constuct writed to screen Dummy: I`m dying! screen destruct Dummy: I`m dying! Actual result: -------------- screen construct dummy constuct screen destruct Fatal error: Call to a member function Write() on a non-object in ... -- Edit bug report at https://bugs.php.net/bug.php?id=61505&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61505&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61505&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61505&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61505&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61505&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61505&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61505&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61505&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61505&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61505&r=support Expected behavior: https://bugs.php.net/fix.php?id=61505&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61505&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61505&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61505&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61505&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61505&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61505&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61505&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61505&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61505&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61505&r=mysqlcfg