php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49090 call_user_func_array modifies internal object context for custom error handler
Submitted: 2009-07-28 17:30 UTC Modified: 2009-07-29 16:19 UTC
From: doctorrock83 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.10 OS: 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: doctorrock83 at gmail dot com
New email:
PHP Version: OS:

 

 [2009-07-28 17:30 UTC] doctorrock83 at gmail dot com
Description:
------------
call_user_func_array() seems to modifies the internal object context while used with set_error_handler();
See the reproduce code.

Note: In the reproduce code, when not using call_user_func_array() (direct function call), there is no problem and the expected behavior occurs.

Reproduce code:
---------------
<?php
class Foo
{
    public function call()
    {
        set_error_handler(array($this, '_errors'));
        $result = call_user_func_array('ucfirst', array());
    }
    
    protected function _errors($errno, $errstr)
    {
        throw new Exception($errstr);
    }
}

$f = new Foo;
$f->call();

Expected result:
----------------
Exception thrown with the message telling that ucfirst accept one parameter, none given

Actual result:
--------------
Fatal error: Call to protected method Foo::_errors() from context '' in /path/to/script.php on line XXX


PHP 5.3.0 returns :

Warning: Invalid callback Foo::_errors, cannot access protected method Foo::_errors() in /path/to/script.php on line XXX

Warning: ucfirst() expects exactly 1 parameter, 0 given in /path/to/script.php on line XXX

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-28 18:29 UTC] jani@php.net
That's quite expected output. What exactly are you saying the bug is?
 [2009-07-28 19:02 UTC] doctorrock83 at gmail dot com
Well call_user_func_array() actually generates an error which is not trapped in the custom error handler as it should be)
 [2009-07-28 19:18 UTC] jani@php.net
Setting the error handler fails, so why should it be used..?
 [2009-07-29 07:29 UTC] doctorrock83 at gmail dot com
setting the error handler works, however it doesn't get called)
 [2009-07-29 13:56 UTC] jani@php.net
Try doing 'var_dump()' on the call to set_error_handler() and you'll see it returns NULL which means it never registered your invalid error handler callback.
 [2009-07-29 16:19 UTC] doctorrock83 at gmail dot com
How do you then explain that just replacing
$result = call_user_func_array('ucfirst', array());
by
ucfirst();

makes PHP go into the custom error handler function ?)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 14:01:33 2025 UTC