note 123716 added to function.is-callable
| From: | jlh@php.net | Date: | Fri, 22 Mar 2019 09:28:32 +0000 |
| Subject: | note 123716 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210423@lists.php.net to get a copy of this message | ||
The story about __call() is a bit more complicated unfortunately. It will always return true ONLY if
you pass an instance of a class, not if you pass the class name itself:
<?php
class MyClass {
public function method() { }
public function __call($name, $arguments) { }
}
is_callable([MyClass::class, 'method']); // true
is_callable([new MyClass(), 'method']); // true
is_callable([MyClass::class, 'other']); // false!!!
is_callable([new MyClass(), 'other'])); // true
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 85.195.255.242)
----
Manual Page -- http://php.net/manual/en/function.is-callable.php
Edit -- https://master.php.net/note/edit/123716
Del: integrated -- https://master.php.net/note/delete/123716/integrated
Del: useless -- https://master.php.net/note/delete/123716/useless
Del: bad code -- https://master.php.net/note/delete/123716/bad+code
Del: spam -- https://master.php.net/note/delete/123716/spam
Del: non-english -- https://master.php.net/note/delete/123716/non-english
Del: in docs -- https://master.php.net/note/delete/123716/in+docs
Del: other reasons-- https://master.php.net/note/delete/123716
Reject -- https://master.php.net/note/reject/123716
Search -- https://master.php.net/manage/user-notes.php