Also fix indentation of __toString().
zend_class_constant *c;
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
- zval_update_constant_ex(&c->value, NULL);
- _class_const_string(str, ZSTR_VAL(key), c, indent);
+ zval_update_constant_ex(&c->value, c->ce);
+ _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent.buf));
} ZEND_HASH_FOREACH_END();
}
string_printf(str, "%s }\n", indent);
/* {{{ _class_const_string */
static void _class_const_string(string *str, char *name, zend_class_constant *c, char *indent)
{
- char *type = zend_zval_type_name(&c->value);
char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value));
- zend_string *value_str = zval_get_string(&c->value);
+ zend_string *value_str;
+ char *type;
- string_printf(str, "%s Constant [ %s %s %s ] { %s }\n",
+ zval_update_constant_ex(&c->value, c->ce);
+ value_str = zval_get_string(&c->value);
+ type = zend_zval_type_name(&c->value);
+
+ string_printf(str, "%sConstant [ %s %s %s ] { %s }\n",
indent, visibility, type, name, ZSTR_VAL(value_str));
zend_string_release(value_str);
GET_REFLECTION_OBJECT_PTR(ref);
ZVAL_DUP(return_value, &ref->value);
+ if (Z_CONSTANT_P(return_value)) {
+ zval_update_constant_ex(return_value, ref->ce);
+ }
}
/* }}} */
Reflecting on class constant TestClass::PUB
__toString():
-string(42) " Constant [ public boolean PUB ] { 1 }
+string(38) "Constant [ public boolean PUB ] { 1 }
"
export():
-string(42) " Constant [ public boolean PUB ] { 1 }
+string(38) "Constant [ public boolean PUB ] { 1 }
"
export():
- Constant [ public boolean PUB ] { 1 }
+Constant [ public boolean PUB ] { 1 }
NULL
getName():
Reflecting on class constant TestClass::PROT
__toString():
-string(46) " Constant [ protected integer PROT ] { 4 }
+string(42) "Constant [ protected integer PROT ] { 4 }
"
export():
-string(46) " Constant [ protected integer PROT ] { 4 }
+string(42) "Constant [ protected integer PROT ] { 4 }
"
export():
- Constant [ protected integer PROT ] { 4 }
+Constant [ protected integer PROT ] { 4 }
NULL
getName():
Reflecting on class constant TestClass::PRIV
__toString():
-string(49) " Constant [ private string PRIV ] { keepOut }
+string(45) "Constant [ private string PRIV ] { keepOut }
"
export():
-string(49) " Constant [ private string PRIV ] { keepOut }
+string(45) "Constant [ private string PRIV ] { keepOut }
"
export():
- Constant [ private string PRIV ] { keepOut }
+Constant [ private string PRIV ] { keepOut }
NULL
getName():
Reflecting on class constant TestClass::PRIV
__toString():
-string(49) " Constant [ private string PRIV ] { keepOut }
+string(45) "Constant [ private string PRIV ] { keepOut }
"
export():
-string(49) " Constant [ private string PRIV ] { keepOut }
+string(45) "Constant [ private string PRIV ] { keepOut }
"
export():
- Constant [ private string PRIV ] { keepOut }
+Constant [ private string PRIV ] { keepOut }
NULL
getName():
--- /dev/null
+--TEST--
+Test variations of getting constant values
+--FILE--
+<?php
+
+/* Use separate classes to make sure that in-place constant updates don't interfere */
+class A {
+ const X = self::Y * 2;
+ const Y = 1;
+}
+class B {
+ const X = self::Y * 2;
+ const Y = 1;
+}
+class C {
+ const X = self::Y * 2;
+ const Y = 1;
+}
+
+var_dump((new ReflectionClassConstant('A', 'X'))->getValue());
+echo new ReflectionClassConstant('B', 'X');
+echo new ReflectionClass('C');
+
+?>
+--EXPECTF--
+int(2)
+Constant [ public integer X ] { 2 }
+Class [ <user> class C ] {
+ @@ %s 12-15
+
+ - Constants [2] {
+ Constant [ public integer X ] { 2 }
+ Constant [ public integer Y ] { 1 }
+ }
+
+ - Static properties [0] {
+ }
+
+ - Static methods [0] {
+ }
+
+ - Properties [0] {
+ }
+
+ - Methods [0] {
+ }
+}