|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39884 ReflectionParameter::getClass() throws exception for type hint self
Submitted: 2006-12-19 13:18 UTC Modified: 2006-12-22 15:39 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugs at php dot frankkleine dot de Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2.0 OS:
Private report: No CVE-ID:
 [2006-12-19 13:18 UTC] bugs at php dot frankkleine dot de
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:
class stubParamTest
    function paramTest(self $param)
        // nothing to do
$test1 = new stubParamTest();
$test2 = new stubParamTest();
$refParam = new ReflectionParameter(array('stubParamTest', 'paramTest'), 'param');

Expected result:
  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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-19 14:40 UTC]
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 14:44 UTC] (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 15:13 UTC] verifies the new functionality
 [2006-12-19 17:03 UTC]

Patch for PHP_5_2 branch
 [2006-12-22 15:39 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 11:01:54 2015 UTC