Bug #71722 [Opn->Dup]: PHP destructor order is arbitrary with static objects

From: Date: Sat, 26 Mar 2016 23:48:03 +0000
Subject: Bug #71722 [Opn->Dup]: PHP destructor order is arbitrary with static objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200136@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71722&edit=1 ID: 71722 Updated by: nikic@php.net Reported by: me at chelseau dot com Summary: PHP destructor order is arbitrary with static objects -Status: Open +Status: Duplicate Type: Bug Package: Unknown/Other Function Operating System: Mac OSX PHP Version: Irrelevant Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2016-03-26 23:45:09] nikic@php.net Related To: Bug #53769 ------------------------------------------------------------------------ [2016-03-26 23:42:53] nikic@php.net Duplicate of bug #53769. ------------------------------------------------------------------------ [2016-03-06 14:50:51] me at chelseau dot com 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 this bug report at https://bugs.php.net/bug.php?id=71722&edit=1

« previous php.bugs (#200136) next »