php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39381 __destruct bug
Submitted: 2006-11-04 19:18 UTC Modified: 2007-02-10 19:35 UTC
Votes:28
Avg. Score:4.6 ± 0.8
Reproduced:28 of 28 (100.0%)
Same Version:24 (85.7%)
Same OS:15 (53.6%)
From: tikitiki at mybboard dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.0 OS: Not Applicable
Private report: No CVE-ID: None
 [2006-11-04 19:18 UTC] tikitiki at mybboard dot com
Description:
------------
If functions are called within __destruct without register_shutdown_function being called on __destruct within a class, and global variables that are classes will not work. This is a bug specificly with PHP 5.2.0.

This bug was reported multiple times at my discussion system (here http://community.mybboard.net/showthread.php?tid=13506 and here http://community.mybboard.net/showthread.php?tid=12430). Calling register_shutdown_function on __destruct, I was able to use that as a workaround, but the problem remains with  __destruct. Please contact me with any information you need, and I will gladly assist you.

Reproduce code:
---------------
You can install a fresh version of MyBB 1.2 here: http://mybboard.com/downloads.php using PHP 5.2.0. The problems lay in inc/class_core.php

Expected result:
----------------
No error, shutdown functions should run properly

Actual result:
--------------
Fatal error: Call to a member function run_hooks() on a non-object in /www/xxx/pub/inc/functions.php on line 146 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-04 19:20 UTC] rygorde4 at sbcglobal dot net
Description:
------------
If functions are called within __destruct without
register_shutdown_function being called on __destruct within a class,
and global variables (that are assigned classes) called in that class will not work. This is a bug
specificly with PHP 5.2.0.

This bug was reported multiple times at my discussion system (here
http://community.mybboard.net/showthread.php?tid=13506 and here
http://community.mybboard.net/showthread.php?tid=12430). Calling
register_shutdown_function on __destruct, I was able to use that as a
workaround, but the problem remains with  __destruct. Please contact me
with any information you need, and I will gladly assist you.

Reproduce code:
---------------
You can install a fresh version of MyBB 1.2 here:
http://mybboard.com/downloads.php using PHP 5.2.0. The problems lay in
inc/class_core.php

Expected result:
----------------
No error, shutdown functions should run properly

Actual result:
--------------
Fatal error: Call to a member function run_hooks() on a non-object in
/www/xxx/pub/inc/functions.php on line 146
 [2006-11-05 15:34 UTC] linksys at yahoo dot com
The same issue occurs in ZenCart v1.3.6 with PHP 5.2.0 regarding using class as global variable. Discussions are here:
http://www.zen-cart.com/forum/showthread.php?t=50534
 [2006-11-06 13:42 UTC] c dot boulton at mybboard dot com
Maybe relates to this?
http://bugs.php.net/bug.php?id=36759
 [2006-11-06 16:46 UTC] harveyelliott at hotmail dot com
I currently get a issue with php 5.2 with ZenCart. I roll back to php 5.1.6 and it works fine... of course its all due to this php 5.2 bug...

Im curently stuck in a hard place.. because.. Im a Web Hosting provider..

So either.. I run php 5.2 to get the security fixes and my customers are SOL that has issues with this bug..


Or.. run insecure code to keep my customers happy..


My question is.. any idea when this is going to be fixed?
If I asked in the wrong place... please direct me to the correct place... as this is very important to me...
 [2006-11-08 13:44 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-11-09 02:37 UTC] Nikolas dot hagelstein at gmail dot com
Same at wordpress 2.05 using php5.2:
 PHP Fatal error:  Call to a member function get() on a non-object in /var/www/www.trashboard.de/htdocs                      /wp-includes/cache.php on line 28
Reverting to 5.1.6 made it work again
 [2006-11-10 16:08 UTC] tikitiki at mybboard dot com
Reproduce code:
---------------
<?php
function run_shutdown() {
	global $x;
	echo __FUNCTION__."\n";
        $x->do_something();
}

class Foo {
  function do_something() {
    echo "hi\n";
  }
  function __destruct() {
    echo __METHOD__."\n";    
  }
}

class Bar {
  
  function __destruct() {
    run_shutdown();
    echo __METHOD__."\n";
  }
}
$y = new Bar();
$x = new Foo();
?>

Expected result:
----------------
Bar::__destruct
run_shutdown
hi
Foo::__destruct

Actual result:
--------------
Foo::__destruct 
run_shutdown
Fatal error: Call to a member function do_something() on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 5
 [2006-11-10 16:15 UTC] tony2001@php.net
There is no certain order of object destruction, there never was and this is explained in many other reports.
You have to take care of the correct destruction order yourself.
 [2006-11-11 00:58 UTC] rygorde4 at sbcglobal dot net
http://bugs.php.net/bug.php?id=36759 ???

How come it is different in PHP 5.2.0? A lot of programs are corrupt because of this 'change'.

Will being able to call register_shutdown_function on __destruct fix this, regardless of php version?
 [2006-11-12 16:57 UTC] rygorde4 at sbcglobal dot net
this is a PHP 5.2.0 error which causes the classes to be destructed in the reverse way they are initialized. If this change was intended for PHP 5.2.0, then you should have given us a heads up before you went releasing software that broke a whole ton of scripts.
This IS a error on PHP 5.2.0, the PHP team should consider unbogusing the report.
 [2006-11-13 15:54 UTC] tikitiki at mybboard dot com
C'mon Guys... Hear me out here.

The classes in PHP 5.2.0 have been changed to destruct in the reverse order that they've been initialized. Why I ask? I hope the change was not 'just because'. And if the change was intentional, you guys should have known that it would affect many scripts. Does it not make more sense to destruct classes in the order they were initialized in the first place?
 [2007-02-10 14:42 UTC] jacques@php.net
This one has hit me using the PEAR HTTP_Session class using the PEAR DB driver.  No sessions were being stored in the database.
 [2007-02-10 19:35 UTC] cellog@php.net
HTTP_Session and DB are php4-based code with no 
__destruct() methods.  moving back to bogus as the last 
comment relates to a different issue (shutdown functions) 
and not to class destructors.  It would be better to write 
an email to pear-general@lists.php.net asking for 
assistance with this issue, to determine whether there is 
a bug in HTTP_Session, or perhaps DB, before reporting 
again as a PHP bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 13:01:32 2024 UTC