php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80323 is_callable() not same to type "callable"
Submitted: 2020-11-05 17:59 UTC Modified: 2020-11-06 13:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: antonfedonyuk at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.2.34 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: antonfedonyuk at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-05 18:03 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2020-11-05 18:03 UTC] nikic@php.net
I can't reproduce this: https://3v4l.org/Q10AR

The call does not produce an error.
 [2020-11-05 18:20 UTC] levim@php.net
We had bugs in differences in `is_callable` and `callable` in the past, haven't we? Or maybe it was in `is_callable`/`callable` and actually calling it. I wonder if we could specifically fuzz this.
 [2020-11-05 18:48 UTC] antonfedonyuk at gmail dot com
-Status: Feedback +Status: Open
 [2020-11-05 18:48 UTC] antonfedonyuk at gmail dot com
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);
?>
 [2020-11-05 19:15 UTC] levim@php.net
-Status: Open +Status: Feedback
 [2020-11-05 19:15 UTC] levim@php.net
The "new" bug isn't a bug at all; you are calling `Test::callback` without an object and it is not marked as static. Can you provide a reproduction case for the first bug?
 [2020-11-05 19:29 UTC] antonfedonyuk at gmail dot com
-Status: Feedback +Status: Open
 [2020-11-05 19:29 UTC] antonfedonyuk at gmail dot com
> levim@php.net "you are calling `Test::callback` without an object and it is not marked as statiс"

Congratulations, devs find 2 new bugs! 

Or you don't see any problem here? (:
 [2020-11-05 19:35 UTC] antonfedonyuk at gmail dot com
> 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);
?>
 [2020-11-05 21:13 UTC] girgias@php.net
-Status: Open +Status: Not a bug
 [2020-11-05 21:13 UTC] girgias@php.net
I'm having troubled understanding what you're going at, a deprecation warning is different from an error.

If you try your last script in PHP 8, (were the deprecation was enacted) you get false and while attempting to call it you'll get a Fatal Error: https://3v4l.org/ilbYM

Something which you don't get in PHP 7.x and thus it is callable, deprecated behaviour but callable.

Same thing with your first example: https://3v4l.org/USs5U
 [2020-11-05 21:26 UTC] antonfedonyuk at gmail dot com
> girgias@php.net "If you try your last script in PHP 8"

we don't talk about any version, please stop trolling
 [2020-11-06 13:41 UTC] girgias@php.net
Again this is expected behaviour for PHP 7, so if you could stop trolling your self and wasting time of maintainers that would be great.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC