#39884 [Asn->Opn]: ReflectionParameter::getClass() throws exception for type hint self
| From: | thekid@php.net | Date: | Tue, 19 Dec 2006 15:13:31 +0000 |
| Subject: | #39884 [Asn->Opn]: ReflectionParameter::getClass() throws exception for type hint self | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-106577@lists.php.net to get a copy of this message | ||
ID: 39884
Updated by: thekid@php.net
Reported By: bugs at php dot frankkleine dot de
-Status: Assigned
+Status: Open
Bug Type: Unknown/Other Function
PHP Version: 5.2.0
Assigned To: helly
New Comment:
http://sitten-polizei.de/bug39884.phpt verifies
the new functionality
Previous Comments:
------------------------------------------------------------------------
[2006-12-19 14:44:14] thekid@php.net
http://sitten-polizei.de/bug39884.diff (CVS
HEAD = PHP6, is probably
easily backportable to 5.2)
Might need some work with Unicode, I haven't patched PHP in quite a
while and have lost track of how Unicode semantics work in
extensions...
------------------------------------------------------------------------
[2006-12-19 14:40:55] thekid@php.net
Same goes for "parent" which works as type hint but will make
reflection try to look up a class called "parent" (and thus throw an
exception)
------------------------------------------------------------------------
[2006-12-19 13:18:21] bugs at php dot frankkleine dot de
Description:
------------
The ReflectionParameter::getClass() method does not work properly if
the reflected parameter uses "self" as type hint. Instead, a
ReflectionException is thrown saying that the class "self" does not
exist. Tested with 5.2 and 6.0.0-dev from Nov 22.
Reproduce code:
---------------
<?php
class stubParamTest
{
function paramTest(self $param)
{
// nothing to do
}
}
$test1 = new stubParamTest();
$test2 = new stubParamTest();
$test1->paramTest($test2);
$refParam = new ReflectionParameter(array('stubParamTest',
'paramTest'), 'param');
var_dump($refParam->getClass());
?>
Expected result:
----------------
object(ReflectionClass)[4]
public 'name' => 'stubParamTest' (length=13)
Actual result:
--------------
Fatal error: Uncaught exception 'ReflectionException' with message
'Class self does not exist' in
C:\apachefriends\xampp1.5.3a\xampp\htdocs\tests\type_hint_self.php:13
Stack trace: #0
C:\apachefriends\xampp1.5.3a\xampp\htdocs\tests\type_hint_self.php(13):
ReflectionParameter->getClass() #1 {main} thrown in
C:\apachefriends\xampp1.5.3a\xampp\htdocs\tests\type_hint_self.php on
line 13
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39884&edit=1