php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63668 Unable to replicate method signature if the method uses "self"
Submitted: 2012-12-02 09:41 UTC Modified: 2018-09-29 17:12 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dev at jurajsplayground dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 5.4.9 OS: Linux/GNU
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: dev at jurajsplayground dot com
New email:
PHP Version: OS:

 

 [2012-12-02 09:41 UTC] 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;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-29 17:12 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2018-09-29 17:12 UTC] nikic@php.net
Since PHP 7 it is possible to retrieve this information through ReflectionType. See https://3v4l.org/nM5RO for an example.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC