|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38465 ReflectionParameter fails if default value is an access to self::
Submitted: 2006-08-15 10:55 UTC Modified: 2006-10-18 16:38 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: baldurien at bbnwn dot eu Assigned: johannes (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
 [2006-08-15 10:55 UTC] baldurien at bbnwn dot eu
While it is possible to use a class constant as default parameter, and while it is possible to use in the form of "self::X", this does not work when we try to reflect such parameter (see below).

It was tested with php5.1.4 (my default version), php5.2-win32-200608150830, and php6.0-win32-200608150830.

If using a class constant as a default parameter is not possible, then it should be said in the doc :

Don't not say much.

Reproduce code:
class Foo {
  const X = 1;
  public function x($x = self::X) {}
$clazz = new ReflectionClass('Foo');
$method = $clazz->getMethod('x');
foreach ($method->getParameters() as $param) {
  if ( $param->isDefaultValueAvailable())
    echo '$', $param->getName(), ' : ', $param->getDefaultValue(), "\n";

Expected result:
should work, eg: display $x = 1

Actual result:
Fatal error: Cannot access self:: when no class scope is active in D:\documents\xxx\desktop\php6.0-win32-200608150830\truc.php on line 10


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-18 16:38 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-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 23 19:01:26 2020 UTC