ID: 36687
User updated by: elias at adaptiveinstance dot com
Reported By: elias at adaptiveinstance dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5CVS-2006-03-10 (snap)
Assigned To: johannes
New Comment:
In that case i must understand anythink completely wrong or...
---code
class Foo
{
function myMeth($param0){}
}
$class = new ReflectionClass('Foo');
$params = $class->getMethod('myMeth')->getParameters();
var_dump($params[0]->getDeclaringClass());
---output
NULL
---end
...NULL is the declaring class.
Previous Comments:
------------------------------------------------------------------------
[2006-03-11 18:34:09] [EMAIL PROTECTED]
It definitively returns which class declared the parameter.
You are in RelfectionParameter here not in RelfectionTypeHint which
doesn't exist.
------------------------------------------------------------------------
[2006-03-11 18:30:00] elias at adaptiveinstance dot com
Alias or not, getDeclaringClass does not return the 'declaring' class
and i don't think someone expects this.
getTypeHintClass sounds good.
------------------------------------------------------------------------
[2006-03-11 17:08:21] [EMAIL PROTECTED]
getClass() is an alias for getDeclaringClass() in 5.1 and will be
dropped in later versions.
What you want is a new method maybe named getParameterClass() or
getTypeHintClass().
------------------------------------------------------------------------
[2006-03-10 22:19:12] elias at adaptiveinstance dot com
Description:
------------
The method ReflectionParameter::getDeclaringClass() always return the
wrong result. I should reaturn the reflection object of the declaring
class and not that of the typehint class.
Further this method has been introduced somewhere between php 5.0.5 and
5.1.3, but the documentation doesn't mention it.
Reproduce code:
---------------
class OtherClass {}
class MyClass
{
function myMeth(OtherClass $param0, $param1){}
}
$class = new ReflectionClass('MyClass');
$params = $class->getMethod('myMeth')->getParameters();
var_dump($params[0]->getDeclaringClass());
var_dump($params[0]->getClass());
var_dump($params[1]->getDeclaringClass());
var_dump($params[1]->getClass());
Expected result:
----------------
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "MyClass"
}
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "OtherClass"
}
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "MyClass"
}
NULL
Actual result:
--------------
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "OtherClass"
}
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "OtherClass"
}
NULL
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36687&edit=1