note 119683 added to reflectionclass.hasmethod
| From: | flancer64 at gmail dot com | Date: | Tue, 02 Aug 2016 10:50:06 +0000 |
| Subject: | note 119683 added to reflectionclass.hasmethod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206151@lists.php.net to get a copy of this message | ||
Annotated methods that are implemented using PHP magic methods are not recognized by
"hasMethod".
<?php
/**
* @method void annotatedMethod()
*/
class SomeClass
{
public function __call($name, $arguments)
{
echo "this is magic method: $name.\n";
}
public function codedMethod()
{
echo "this is coded method.\n";
}
}
$obj = new \SomeClass();
$obj->codedMethod();
$obj->annotatedMethod();
$ref = new ReflectionClass(\SomeClass::class);
echo "SomeClass has 'codedMethod': " .
json_encode($ref->hasMethod('codedMethod')) . ".\n";
echo "SomeClass has 'annotatedMethod': " .
json_encode($ref->hasMethod('annotatedMethod')) . ".\n";
?>
Output:
this is coded method.
this is magic method: annotatedMethod.
SomeClass has 'codedMethod': true.
SomeClass has 'annotatedMethod': false.
----
Server IP: 72.52.91.14
Probable Submitter: 195.122.16.242
----
Manual Page -- http://php.net/manual/en/reflectionclass.hasmethod.php
Edit -- https://master.php.net/note/edit/119683
Del: integrated -- https://master.php.net/note/delete/119683/integrated
Del: useless -- https://master.php.net/note/delete/119683/useless
Del: bad code -- https://master.php.net/note/delete/119683/bad+code
Del: spam -- https://master.php.net/note/delete/119683/spam
Del: non-english -- https://master.php.net/note/delete/119683/non-english
Del: in docs -- https://master.php.net/note/delete/119683/in+docs
Del: other reasons-- https://master.php.net/note/delete/119683
Reject -- https://master.php.net/note/reject/119683
Search -- https://master.php.net/manage/user-notes.php