note 126199 added to function.is-callable
| From: | mohamed dot elidrissi at protonmail dot com | Date: | Mon, 28 Jun 2021 12:26:25 +0000 |
| Subject: | note 126199 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216553@lists.php.net to get a copy of this message | ||
Note that -- as mentioned in the migration guide-- starting from PHP 8.0, is_callable() will not
work with non-static methods if you use a class name, instead an object of the class should be
provided:
<?php
class Test
{
public function method1() { }
public static function method2() { }
}
// Pre PHP 8
var_dump(is_callable(array('Test', 'method1'))); // bool(true)
var_dump(is_callable(array('Test', 'method2'))); // bool(true)
// Post PHP 8
var_dump(is_callable(array('Test', 'method1'))); // bool(false)
var_dump(is_callable(array('Test', 'method2'))); // bool(true)
var_dump(is_callable(array(new Test, 'method1'))); // bool(true)
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 196.75.93.232)
----
Manual Page -- https://php.net/manual/en/function.is-callable.php
Edit -- https://main.php.net/note/edit/126199
Del: integrated -- https://main.php.net/note/delete/126199/integrated
Del: useless -- https://main.php.net/note/delete/126199/useless
Del: bad code -- https://main.php.net/note/delete/126199/bad+code
Del: spam -- https://main.php.net/note/delete/126199/spam
Del: non-english -- https://main.php.net/note/delete/126199/non-english
Del: in docs -- https://main.php.net/note/delete/126199/in+docs
Del: other reasons-- https://main.php.net/note/delete/126199
Reject -- https://main.php.net/note/reject/126199
Search -- https://main.php.net/manage/user-notes.php