php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52250 ReflectionParameter::getDefaultValue for array with consts
Submitted: 2010-07-05 10:52 UTC Modified: 2010-07-05 14:03 UTC
From: nikita at rusoft dot ru Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.2.13 OS: linux
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: nikita at rusoft dot ru
New email:
PHP Version: OS:

 

 [2010-07-05 10:52 UTC] nikita at rusoft dot ru
Description:
------------
If I used ReflectionParameter for method parametr that include default value with 
array, I couldn't get its defaultValue.

Fatal error is throws:
"PHP Fatal error:  Undefined class constant 'self::CONST_NAME' in /path/file.php 
on line NNN".

See test script.

Tested on php 5.2.13, php 5.3.2.

Test script:
---------------
<?php
class A {
    const B = 'BB';
    const C = 'CC';

    public function some(array $param = array(self::B, self::C))
    {
        var_export($param);
    }
}

$refClass = new ReflectionClass('A');
$refMethods = $refClass->getMethod('some')->getParameters();

$refMethod = array_pop($refMethods);
if ($refMethod->isDefaultValueAvailable()) {
    var_export($refMethod->getDefaultValue()); //Fatal error
}

Expected result:
----------------
array (
  0 => 'BB',
  1 => 'CC',
)

Actual result:
--------------
PHP Fatal error:  Cannot access self:: when no class scope is active in test.php 
on line 15

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-05 13:50 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: johannes
 [2010-07-05 13:59 UTC] felipe@php.net
-Status: Assigned +Status: Bogus -Assigned To: johannes +Assigned To:
 [2010-07-05 13:59 UTC] felipe@php.net
Hello, this bug was already fixed in SVN. See bug #51905
For your information the fix was included in the PHP 5.2.14RC1.

Thanks.
 [2010-07-05 14:03 UTC] nikita at rusoft dot ru
Thank you. I will wait next release.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC