php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43231 array-based callback syntax is overly E_STRICT
Submitted: 2007-11-10 03:20 UTC Modified: 2008-02-03 04:27 UTC
Votes:16
Avg. Score:4.8 ± 0.4
Reproduced:13 of 16 (81.2%)
Same Version:12 (92.3%)
Same OS:5 (38.5%)
From: chuck at horde dot org Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.* OS: *
Private report: No CVE-ID: None
 [2007-11-10 03:20 UTC] chuck at horde dot org
Description:
------------
The callback syntax of array('classname', 'methodname') for making static method calls is now enforcing E_STRICT even if E_STRICT is not on. So methods that are not explicitly declared static can't be used this way even with E_STRICT off. Putting static in front of the function makes it work, but of course results in a parse error when the code is run under PHP 4.

Reproduce code:
---------------
<?php

class Test {
    function hello() {
        echo "hello\n";
    }
}

call_user_func(array('Test', 'hello'));

Expected result:
----------------
hello

Actual result:
--------------
Warning: call_user_func() expects parameter 1 to be valid callback, array given in /Users/chuck/callback.php on line 11

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-10 10:32 UTC] johannes@php.net
I already have a patch for that, will commit that once I'll boot the other system
 [2007-11-14 08:03 UTC] jani@php.net
And this is HEAD issue too, that's where I simply MFH'd the stuff that broke this. :)
 [2007-11-25 20:08 UTC] chagenbu@php.net
Just a reminder on this, since you said you already had the patch?
 [2008-01-17 06:11 UTC] chagenbu@php.net
Ping?
 [2008-01-30 19:20 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is indeed the correct behavior. You do not pass in a valid callback. If you call hello() directly you get an E_STRICT. Now call_user_func[_array]() tries to bind this function and cannot because it is not a valid one. It used to work in 5.2 for BC sakes, because I overlooked this in 5.0. When I first noticed this issue in 5.1, we couldn't change it in 5.1 and we also decided to not change this in 5.2.
 [2008-01-30 19:25 UTC] chagenbu@php.net
I'm sorry, I don't understand. Of course it is an E_STRICT error. But why is it an error if E_STRICT is turned off?
 [2008-01-31 15:30 UTC] jason at citydiesel dot net
I also don't understand.  It seems to me that this logic will lead to a lot of unnecessary compatibility issues.  If we need the strict behavior we can always set E_STRICT.
 [2008-01-31 16:48 UTC] mike at theupstairsroom dot com
This is insane. You should not produce an E_STRICT error if E_STRICT is turned off. This will break a *lot* of existing code...
 [2008-02-01 08:58 UTC] jochem at mondrian dot nl
I agree that this should be a bug, a lot of applications that try to be compatible with both php4 and php5 will run into this.

I know everyone should run PHP5, but reality is that many people don't yet, or can't yet.
 [2008-02-01 22:56 UTC] jani@php.net
Wasn't this fixed now..?
 [2008-02-01 23:22 UTC] rasmus@php.net
This is fixed in CVS now.
 [2008-02-03 04:27 UTC] chagenbu@php.net
Thank you, to Marcus especially.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC