php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72846 getConstant for a array constant with constant values returns NULL/NFC/UKNOWN
Submitted: 2016-08-15 15:01 UTC Modified: 2016-08-15 15:15 UTC
From: info at nepda dot eu Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.0.9 OS: Linux
Private report: No CVE-ID: None
 [2016-08-15 15:01 UTC] info at nepda dot eu
Description:
------------
If you have any namespace (e.g. "Some") and a (abstract or concrete) class (e.g. "A") with some constants in it and a class (e.g. "B") extending "A", the reflection class is not able to get the constant values of an array constant with constant values in it.

See example code.

Output with PHP 7.0.9:

    see "Actual result:"

with PHP 5.6.24 it's working:

    see "Expected result:"

Without the namespace, it's working on both versions.

Test script:
---------------
<?php

namespace Some {

    abstract class A
    {
        const ONE = '1';
        const TWO = '2';

        const CONST_NUMBERS = [
            self::ONE,
            self::TWO,
        ];

        const NUMBERS = [
            '1',
            '2',
        ];
    }

    class B extends A
    {
    }

    $ref = new \ReflectionClass('Some\B');

    var_dump($ref->getConstant('ONE'));
    var_dump($ref->getConstant('CONST_NUMBERS'));
    var_dump($ref->getConstant('NUMBERS'));
}


Expected result:
----------------
string(1) "1"
array(2) {
    [0]=>
  string(1) "1"
    [1]=>
  string(1) "2"
}
array(2) {
    [0]=>
  int(10)
  [1]=>
  int(11)
}

Actual result:
--------------
string(1) "1"
UNKNOWN:0
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-15 15:15 UTC] info at nepda dot eu
With PHP 7.1*beta* it's working too.
 [2016-08-15 15:25 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=60de74ebdae5cf8b14f85d6e60f519c9e8b966f9
Log: Fixed bug #72846 (getConstant for a array constant with constant values returns NULL/NFC/UKNOWN)
 [2016-08-15 15:25 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-10-17 10:09 UTC] bwoebi@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=60de74ebdae5cf8b14f85d6e60f519c9e8b966f9
Log: Fixed bug #72846 (getConstant for a array constant with constant values returns NULL/NFC/UKNOWN)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC