Doc #70160 [Opn->Ver]: string with double colon is callable, but cannot be called
| From: | cmb@php.net | Date: | Tue, 28 Jul 2015 18:52:13 +0000 |
| Subject: | Doc #70160 [Opn->Ver]: string with double colon is callable, but cannot be called | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12562@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70160&edit=1
ID: 70160
Updated by: cmb@php.net
Reported by: cf0hay at gmail dot com
Summary: string with double colon is callable, but cannot be
called
-Status: Open
+Status: Verified
Type: Documentation Problem
-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
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2015-07-28 15:34:46] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70160&edit=1