]> granicus.if.org Git - php/commitdiff
Check update constant failure in ReflectionClassConstant::__toString()
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 31 Aug 2020 12:49:16 +0000 (14:49 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 31 Aug 2020 12:50:20 +0000 (14:50 +0200)
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionClassConstant_toString_error.phpt [new file with mode: 0644]

index f62dd15e1c90e0c060449831980ce367ddb70be9..df00e5b4ba24a64a1579fc7e167c2c031d3d1931 100644 (file)
@@ -547,7 +547,10 @@ static void _class_const_string(smart_str *str, char *name, zend_class_constant
        char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value));
        char *type;
 
-       zval_update_constant_ex(&c->value, c->ce);
+       if (zval_update_constant_ex(&c->value, c->ce) == FAILURE) {
+               return;
+       }
+
        type = zend_zval_type_name(&c->value);
 
        if (Z_TYPE(c->value) == IS_ARRAY) {
diff --git a/ext/reflection/tests/ReflectionClassConstant_toString_error.phpt b/ext/reflection/tests/ReflectionClassConstant_toString_error.phpt
new file mode 100644 (file)
index 0000000..cd4dfa3
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Exception thrown while converting ReflectionClassConstant to string
+--FILE--
+<?php
+
+class B {
+    const X = self::UNKNOWN;
+}
+
+try {
+    echo new ReflectionClassConstant('B', 'X');
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Undefined class constant 'self::UNKNOWN'