php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34344 register_shutdown_function() in classes
Submitted: 2005-09-02 12:48 UTC Modified: 2005-09-02 16:48 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: thomas at ecommerce dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.0.4 OS: SuSE Linux
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: thomas at ecommerce dot com
New email:
PHP Version: OS:

 

 [2005-09-02 12:48 UTC] thomas at ecommerce dot com
Description:
------------
When trying to call the register_shutdown_function() inside class like this:

register_shutdown_function(array(&$this, "_log"));

and the method _log() is a private method it don't work. We assign $this here to the function so 
register_shutdown_function() should be allowed to call a private function inside of the class or at least throw allready here an error message when this function is called and _log() is a private function. Its also not documented that this wouldn't work....

Reproduce code:
---------------
<?php
final class TestClass
{
        public function TestClass()
        {
                echo "Class init call!\n";
                $this->_init();
        }

        private function _init()
        {
                echo "Registrering shutdown function..\n";

                //-- register log function
                register_shutdown_function(array(&$this, "_log"));

                echo "done\n";
        }

        private function _log()
        {
                        //-- send mail
                mail("thomas@ecommerce.com", "subject", "content");
        }
}

echo "Script start! Init Class.\n";
$TestClass = new TestClass();
echo "Class inited!\n";

Expected result:
----------------
email will be send to thomas@ecommerce.com when script is done.

Actual result:
--------------
Script will not call the shutdown function

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-02 12:53 UTC] thomas at ecommerce dot com
Updated Expected result part
 [2005-09-02 12:54 UTC] thomas at ecommerce dot com
Script start! Init Class.
Class init call!
Registrering shutdown function..
done
Class inited!

Fatal error: Call to private method TestClass::_log() from context '' in Unknown on line 0
----------
is the current result
 [2005-09-02 16:15 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-09-02 16:27 UTC] thomas at ecommerce dot com
Script start! Init Class.
Class init call!
Registrering shutdown function..
done
Class inited!

Warning: (Registered shutdown functions) Unable to call TestClass::_log() - function does not exist in Unknown on line 0
------------------------------
This is the output with the latest CVS Snap. The problem still exists and the Error Message is wrong ( function does not exist, but exists )
 [2005-09-02 16:39 UTC] sniper@php.net
Ah yes, you can't really call any object methods inside a shutdown function since the objects are destructed before that.
 [2005-09-02 16:48 UTC] thomas at ecommerce dot com
does that mean this code will work in PHP5.0 ( when login function is public ) and in PHP5.1 this code won't work anymore?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC