Bug #71722 [NEW]: PHP destructor order is arbitrary with static objects

From: Date: Sun, 06 Mar 2016 14:50:57 +0000
Subject: Bug #71722 [NEW]: PHP destructor order is arbitrary with static objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199628@lists.php.net to get a copy of this message
From: me at chelseau dot com Operating system: Mac OSX PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Bug Bug description:PHP destructor order is arbitrary with static objects Description: ------------ This occurs with all versions of PHP it seems. I've tested with the current snap: PHP 7.1.0-dev (cli) (built: Mar 6 2016 06:13:27) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies To reproduce, store 2 class instances statically. Even if class (Foo) stores a ref to class (Bar), if (Bar) is initialized first it is destructed first, allowing (Foo) to access an object whose destructor has already been called. It seems that objects stored in static (global) refs are destroyed based on those globals only rather than potential local refs. I would expect the destructor for (Foo) to fire first because Foo has a ref to (Bar) Test script: --------------- https://3v4l.org/Ifgn9 Expected result: ---------------- Bar::__construct Foo::__construct Foo::__destruct Bar::func Bar::__destruct Actual result: -------------- Bar::__construct Foo::__construct Bar::__destruct Foo::__destruct Bar::func -- Edit bug report at https://bugs.php.net/bug.php?id=71722&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71722&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71722&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71722&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71722&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71722&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71722&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71722&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71722&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71722&r=support Expected behavior: https://bugs.php.net/fix.php?id=71722&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71722&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71722&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71722&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71722&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71722&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71722&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71722&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71722&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71722&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71722&r=mysqlcfg

« previous php.bugs (#199628) next »