]> granicus.if.org Git - php/commitdiff
Fixed bug #72846 (getConstant for a array constant with constant values returns NULL...
authorXinchen Hui <laruence@gmail.com>
Mon, 15 Aug 2016 15:22:55 +0000 (23:22 +0800)
committerXinchen Hui <laruence@gmail.com>
Mon, 15 Aug 2016 15:22:55 +0000 (23:22 +0800)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug72846.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 968a841fff0845ab9c91acfed174e4a5c554ac80..f58aa0b8603bc259c1b7fa6fb4122dd3246288e4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ PHP                                                                        NEWS
     specifying a sequence). (Pablo Santiago Sánchez, Matteo)
   . Fixed bug #72759 (Regression in pgo_pgsql). (Anatol)
 
+- Reflection:
+  . Fixed bug #72846 (getConstant for a array constant with constant values
+    returns NULL/NFC/UKNOWN). (Laruence)
+
 - Session:
   . Fixed bug #72724 (PHP7: session-uploadprogress kills httpd). (Nikita)
 
index 964e7a9e57fdebe978178f9df87ead2602a34f03..08acc7e5d29600f5c510e05d7d1ab15f3f01615e 100644 (file)
@@ -4407,6 +4407,7 @@ ZEND_METHOD(reflection_class, getConstants)
        GET_REFLECTION_OBJECT_PTR(ce);
        array_init(return_value);
        ZEND_HASH_FOREACH_VAL(&ce->constants_table, val) {
+               ZVAL_DEREF(val);
                if (UNEXPECTED(zval_update_constant_ex(val, 1, ce) != SUCCESS)) {
                        return;
                }
@@ -4431,6 +4432,7 @@ ZEND_METHOD(reflection_class, getConstant)
 
        GET_REFLECTION_OBJECT_PTR(ce);
        ZEND_HASH_FOREACH_VAL(&ce->constants_table, value) {
+               ZVAL_DEREF(value);
                if (UNEXPECTED(zval_update_constant_ex(value, 1, ce) != SUCCESS)) {
                        return;
                }
diff --git a/ext/reflection/tests/bug72846.phpt b/ext/reflection/tests/bug72846.phpt
new file mode 100644 (file)
index 0000000..ab8b6ca
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Bug #72846 (getConstant for a array constant with constant values returns NULL/NFC/UKNOWN)
+--FILE--
+<?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'));
+}
+?>
+--EXPECT--
+string(1) "1"
+array(2) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(1) "2"
+}
+array(2) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(1) "2"
+}