Req #63668 [Opn->Csd]: Unable to replicate method signature if the method uses "self"
| From: | nikic@php.net | Date: | Sat, 29 Sep 2018 17:12:28 +0000 |
| Subject: | Req #63668 [Opn->Csd]: Unable to replicate method signature if the method uses "self" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217289@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63668&edit=1
ID: 63668
Updated by: nikic@php.net
Reported by: dev at jurajsplayground dot com
Summary: Unable to replicate method signature if the method
uses "self"
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Reflection related
Operating System: Linux/GNU
PHP Version: 5.4.9
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Since PHP 7 it is possible to retrieve this information through ReflectionType. See https://3v4l.org/nM5RO for an example.
Previous Comments:
------------------------------------------------------------------------
[2012-12-02 09:41:39] dev at jurajsplayground dot com
Description:
------------
I was trying to mock a ZF class using PHPUnit which has a method that hints a
parameter as "self" rather than using the class name.
ReflectionParameter::getClass() returns the correct class name, however, there
is no way to find out that the actual method signature used "self" rather than
the class name.
See:
https://github.com/sebastianbergmann/phpunit-mock-objects/issues/107
https://github.com/zendframework/zf2/issues/2977
While this behaviour is expected, using echo() on the parameters outputs
"Parameter #0 [ <required> self $merge ]" (we can see it's not
"Config" but
"self") while using getClass() returns the "self" turned into ReflectionClass.
Could another method be added to ReflectionParameter that returns the raw "type
hint", i.e. "self" so that method's signature can be properly replicated for
testing?
Test script:
---------------
class Config {
public function merge(self $merge){
}
}
$ref = new ReflectionMethod("Config", "merge");
echo current($ref->getParameters()) , " ",
current($ref->getParameters())->getClass()->name;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63668&edit=1