[PHP-BUG] Bug #76028 [NEW]: call_user_func($a) and $a() behave differently

[email protected] ("bburnichon at gmail dot com") Wed, 28 Feb 2018 14:33:44 GMT
Newsgroups php.standards
Message-ID <[email protected]>
From:             bburnichon at gmail dot com
Operating system: Linux
PHP version:      5.6.33
Package:          PHP Language Specification
Bug Type:         Bug
Bug description:call_user_func($a) and $a() behave differently

Description:
------------
A callable can be defined as an array containing class and method.

Calling call_user_func() with such an array has no issue.
If you try to use the array as a callable, then 'self' loose its special
meaning and an error is triggered saying class self does not exists.

Test script:
---------------
<?php

class CallBySelf
{
    public static function foo()
    {
        echo 'Foo', PHP_EOL;
    }
    
    public static function testCall()
    {
        $method = ['self', 'foo'];
        var_dump(is_callable($method));
        
        echo 'Call via call_user_func: ';
        call_user_func($method);
        
        echo 'Direct call: ';
        $method();
    }
}

CallBySelf::testCall();

Expected result:
----------------
Call via call_user_func: Foo
Direct call: Foo


Actual result:
--------------
bool(true)
Call via call_user_func: Foo
Direct call: 
Fatal error: Class 'self' not found in /in/Ssgep on line 19


-- 
Edit bug report at https://bugs.php.net/bug.php?id=76028&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=76028&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=76028&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=76028&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=76028&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=76028&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=76028&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=76028&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=76028&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=76028&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=76028&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=76028&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=76028&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=76028&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76028&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=76028&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=76028&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=76028&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76028&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=76028&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=76028&r=mysqlcfg