Doc #70160 [Ver->Csd]: string with double colon is callable, but cannot be called
| From: | cmb@php.net | Date: | Tue, 28 Jul 2015 19:26:00 +0000 |
| Subject: | Doc #70160 [Ver->Csd]: 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-12563@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: Verified
+Status: Closed
Type: Documentation Problem
Package: Variables related
Operating System: *
PHP Version: n/a
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2015-07-28 19:23:20] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=337259
Log: updated variable function documentation (fixes #70160)
------------------------------------------------------------------------
[2015-07-28 18:52:12] 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 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