php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62763 register_shutdown_function and extending class
Submitted: 2012-08-06 22:20 UTC Modified: 2012-08-12 12:59 UTC
From: valentiny510 at yahoo dot es Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.5 OS: XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: valentiny510 at yahoo dot es
New email:
PHP Version: OS:

 

 [2012-08-06 22:20 UTC] valentiny510 at yahoo dot es
Description:
------------
Is a little hard to explain becouse are many scenarios where the shutdown function fail or the php doesn't handle correctly the errors but the most simplest method is shown bellow.

Normally, without the register_shutdown_function works well, but if I add the function into the __construct and the child class does not have defined the __construct then fail.

To work well I need to add the __construct function to the child, but if I dont, why the php doesnt throw me an error with $file, $line etc ?

I have many scripts and different scenarios where fail but this I think is the worst becouse it crush all the server.

Sorry but I cant provide any backtrace in this moment

Test script:
---------------
class test1 {
    public function __construct() {
        register_shutdown_function(array($this, 'shut')); }
    public function shutdown() { exit ('Shutdown'); }
}

class test2 extends test1 {
    public function __destruct() { exit (__METHOD__); }
}

new test1;
new test2;


Expected result:
----------------
test2::__destruct
Shutdown

or

Shutdown
test2::__destruct

depending of the priority

Actual result:
--------------
All server crush and restart


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-06 22:53 UTC] valentiny510 at yahoo dot es
P.S. The functions both "exit" and with "echo" I got this errors:

[06-Aug-2012 23:48:50 UTC] PHP Warning:  (Registered shutdown functions) Unable to call test1::shutdown() - function does not exist in Unknown on line 0

[06-Aug-2012 23:48:50 UTC] PHP Warning:  (Registered shutdown functions) Unable to call test2::shutdown() - function does not exist in Unknown on line 0
 [2012-08-07 01:33 UTC] aharvey@php.net
I get the following error with a debug build of the current 5.4 tree (Linux, 
x86):

adam@eden:~$ php /tmp/test.php
Shutdown
test2::__destruct/home/adam/trees/php-src/5.4/Zend/zend_hash.c(551) : 
ht=0xb6731b50 is being destroyed

I had to alter the script slightly to make it run; what I ended up using was:


<?php
class test1 {
    public function __construct() {
        register_shutdown_function(array($this, 'shutdown')); }
    public function shutdown() { exit ("Shutdown\n"); }
}

class test2 extends test1 {
    public function __destruct() { exit (__METHOD__); }
}

new test1;
new test2;
?>

The backtrace at the point of the consistency check:


Breakpoint 1, zend_hash_destroy (ht=0xb6fb2b1c) at /home/adam/trees/php-
src/5.4/Zend/zend_hash.c:551
551		IS_CONSISTENT(ht);
(gdb) bt
#0  zend_hash_destroy (ht=0xb6fb2b1c) at /home/adam/trees/php-
src/5.4/Zend/zend_hash.c:551
#1  0x084218d5 in php_free_shutdown_functions () at /home/adam/trees/php-
src/5.4/ext/standard/basic_functions.c:5043
#2  0x0842188f in php_call_shutdown_functions () at /home/adam/trees/php-
src/5.4/ext/standard/basic_functions.c:5034
#3  0x0853a400 in php_request_shutdown (dummy=0x0) at /home/adam/trees/php-
src/5.4/main/main.c:1718
#4  0x086d3408 in do_cli (argc=2, argv=0xbffff3a4) at /home/adam/trees/php-
src/5.4/sapi/cli/php_cli.c:1171
#5  0x086d3c03 in main (argc=2, argv=0xbffff3a4) at /home/adam/trees/php-
src/5.4/sapi/cli/php_cli.c:1364
 [2012-08-07 01:33 UTC] aharvey@php.net
-Status: Open +Status: Verified
 [2012-08-07 02:10 UTC] valentiny510 at yahoo dot es
Oh yes, sorry, the function called was just "shut" not "shutdown", sorry for that, the test script was writed with some hurry on the web, it was not copied from the actual script, Thank you Aharvey.
 [2012-08-07 04:52 UTC] valentiny510 at yahoo dot es
P.S. 2 :D Sorry.
The errors...

[07-Aug-2012 05:39:51 UTC] PHP Warning:  (Registered shutdown functions) Unable to call test1::shutdown() - function does not exist in Unknown on line 0

[07-Aug-2012 05:39:51 UTC] PHP Warning:  (Registered shutdown functions) Unable to call test2::shutdown() - function does not exist in Unknown on line 0

are shown when the function "shutdown" is private.

If I "exit" it crush the server but if I "echo" the result is

Shutdown
Shutdown
test2::__destruct

Now.. why it output twice when I dont even called parent::__construct ?

If I add an empty __construct function to the child the output is

test2::__destruct
Shutdown

Note also the called order...
 [2012-08-12 12:55 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4970926e4543c15e16b0c047d85dddfb4c09b581
Log: Fixed bug #62763 (register_shutdown_function and extending class)
 [2012-08-12 12:55 UTC] laruence@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-08-12 12:55 UTC] laruence@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: laruence
 [2012-08-12 12:56 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4970926e4543c15e16b0c047d85dddfb4c09b581
Log: Fixed bug #62763 (register_shutdown_function and extending class)
 [2012-08-12 12:57 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4970926e4543c15e16b0c047d85dddfb4c09b581
Log: Fixed bug #62763 (register_shutdown_function and extending class)
 [2012-08-12 12:59 UTC] laruence@php.net
the fix is only fix the crash or "hash inconsistent" warning.  but leaves a 
memleak. 

but IMO it's the proper way for this.
 [2014-10-07 23:23 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=4970926e4543c15e16b0c047d85dddfb4c09b581
Log: Fixed bug #62763 (register_shutdown_function and extending class)
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=4970926e4543c15e16b0c047d85dddfb4c09b581
Log: Fixed bug #62763 (register_shutdown_function and extending class)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 05:01:27 2024 UTC