php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71722 PHP destructor order is arbitrary with static objects
Submitted: 2016-03-06 14:50 UTC Modified: 2016-03-26 23:48 UTC
From: me at chelseau dot com Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: Irrelevant OS: Mac OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: me at chelseau dot com
New email:
PHP Version: OS:

 

 [2016-03-06 14:50 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-26 23:42 UTC] nikic@php.net
Duplicate of bug #53769.
 [2016-03-26 23:48 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC