Skip to content

Commit 7063b01

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Reflection: show the type of object constants used as default properties
2 parents 0ec6413 + 77847b0 commit 7063b01

5 files changed

+125
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,16 @@ static int format_default_value(smart_str *str, zval *value) {
682682
format_default_value(str, zv);
683683
} ZEND_HASH_FOREACH_END();
684684
smart_str_appendc(str, ']');
685+
} else if (Z_TYPE_P(value) == IS_OBJECT) {
686+
/* This branch is reached if the constant AST was already evaluated and
687+
* resulted in an object; enums are already handled in smart_str_append_zval()
688+
* (GH-15902) */
689+
zend_object *obj = Z_OBJ_P(value);
690+
zend_class_entry *class = obj->ce;
691+
ZEND_ASSERT(!(class->ce_flags & ZEND_ACC_ENUM));
692+
smart_str_appends(str, "object(");
693+
smart_str_append(str, class->name);
694+
smart_str_appends(str, ")");
685695
} else {
686696
ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST);
687697
zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), "");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
ReflectionClass object default property - used to say "callable"
3+
--INI--
4+
opcache.enable_cli=0
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public stdClass $a = FOO;
10+
}
11+
define('FOO', new stdClass);
12+
13+
new C;
14+
15+
$reflector = new ReflectionClass(C::class);
16+
echo $reflector;
17+
?>
18+
--EXPECTF--
19+
Class [ <user> class C ] {
20+
@@ %sReflectionClass-callable.php %d-%d
21+
22+
- Constants [0] {
23+
}
24+
25+
- Static properties [0] {
26+
}
27+
28+
- Static methods [0] {
29+
}
30+
31+
- Properties [1] {
32+
Property [ public stdClass $a = object(stdClass) ]
33+
}
34+
35+
- Methods [0] {
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
ReflectionClass object default property - used to say "__CLASS__"
3+
--INI--
4+
opcache.enable_cli=0
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public stdClass $a = FOO;
10+
}
11+
$reflector = new ReflectionClass(C::class);
12+
13+
define('FOO', new stdClass);
14+
new C;
15+
16+
echo $reflector;
17+
18+
?>
19+
--EXPECTF--
20+
Class [ <user> class C ] {
21+
@@ %sReflectionClass-class.php %d-%d
22+
23+
- Constants [0] {
24+
}
25+
26+
- Static properties [0] {
27+
}
28+
29+
- Static methods [0] {
30+
}
31+
32+
- Properties [1] {
33+
Property [ public stdClass $a = object(stdClass) ]
34+
}
35+
36+
- Methods [0] {
37+
}
38+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
ReflectionProperty object default - used to say "callable"
3+
--INI--
4+
opcache.enable_cli=0
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public stdClass $a = FOO;
10+
}
11+
define('FOO', new stdClass);
12+
13+
new C;
14+
15+
$reflector = new ReflectionProperty(C::class, 'a');
16+
echo $reflector;
17+
18+
?>
19+
--EXPECTF--
20+
Property [ public stdClass $a = object(stdClass) ]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
ReflectionProperty object default - used to say "__CLASS__"
3+
--INI--
4+
opcache.enable_cli=0
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public stdClass $a = FOO;
10+
}
11+
$reflector = new ReflectionProperty(C::class, 'a');
12+
13+
define('FOO', new stdClass);
14+
new C;
15+
16+
echo $reflector;
17+
18+
?>
19+
--EXPECTF--
20+
Property [ public stdClass $a = object(stdClass) ]

0 commit comments

Comments
 (0)