php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70160 string with double colon is callable, but cannot be called
Submitted: 2015-07-28 15:34 UTC Modified: 2015-07-28 19:26 UTC
From: cf0hay at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Variables related
PHP Version: n/a OS: *
Private report: No CVE-ID: None
 [2015-07-28 15:34 UTC] cf0hay at gmail dot com
Description:
------------
callable typehint and is_callable may return true for a string with double colon, but it's not callable with parentheses. On the page

http://php.net/manual/en/language.types.callable.php

"As of PHP 5.2.3, it is also possible to pass 'ClassName::methodName'"

Well, able to pass, but cannot use.

Occurs in PHP 5.6. PHP 7.0 doesn't have this problem, it works properly.

Test script:
---------------
<?php
namespace ns {
    class cls{
        static function sfn(){
            return 'OK';
        }
    }
}

namespace {
    function mycallfn(callable $x){
        if(is_callable($x)){
            return $x();
        }else{
            return 'FAIL';
        }
    }
    echo mycallfn(["ns\\cls", "sfn"])."\n";
    echo mycallfn("ns\\cls::sfn")."\n";
}


Expected result:
----------------
OK
OK


Actual result:
--------------
OK
PHP Fatal error:  Call to undefined function ns\cls::sfn() on line 13


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-28 18:52 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: Documentation problem +Package: Variables related -Operating System: 64bit Linux +Operating System: * -PHP Version: 5.6.11 +PHP Version: n/a -Assigned To: +Assigned To: cmb
 [2015-07-28 18:52 UTC] cmb@php.net
Actually, this is not a problem regarding the callable type hint
or the passing of callables (which works as expected and
documented), but rather a problem regarding variable functions[1].
If you use `return call_user_func($x);` instead of `return $x;`,
the script works fine. See also request #68475, which has been
implemented for PHP 7, but won't be backported to PHP 5.

Anyhow, the documentation of variable functions is rather
incomplete, which should be changed.

[1] <http://php.net/manual/en/functions.variable-functions.php>
 [2015-07-28 19:23 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337259
Log: updated variable function documentation (fixes #70160)
 [2015-07-28 19:26 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-07-28 19:26 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 14:01:24 2019 UTC