|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-11-05 17:59 UTC] antonfedonyuk at gmail dot com
Description:
------------
is_callable() return TRUE when we pass an array that represents a class name and a non-static method. But if we pass that callback to function with "callable" parameter it's generate error.
Test script:
---------------
class Test {
public function callback() {}
public function set(callable $callback) {}
}
$callback = ['Test', 'callback'];
Expected result:
----------------
is_callable($callback); // return FALSE
(new Test())->set($callback); // generate error
Actual result:
--------------
is_callable($callback); // return TRUE
(new Test())->set($callback); // generate error
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 23:00:02 2025 UTC |
nikic@php.net find another bug!!! ))) It's really work fine and not generate errors: <?php class Test { public function callback() {} public function set(callable $callback) {} } $callback = ['Test', 'callback']; var_dump(is_callable($callback)); $a = new Test(); $a->set($callback); ?> But if we separate set() then php generate error "Deprecated: Non-static method Test::callback() should not be called statically in ...": <?php class Test { public function callback() {} } class Test2 { public function set(callable $callback) {} } $callback = ['Test', 'callback']; var_dump(is_callable($callback)); $a = new Test2(); $a->set($callback); ?>> levim@php.net how you test it? that code still generate error (tested in php 7.x): <?php class Test { public function callback() {} } class Test2 { public function set(callable $callback) {} } $callback = 'Test::callback'; var_dump(is_callable($callback)); $a = new Test2(); $a->set($callback); ?>