Skip to content

Commit c4ac008

Browse files
committed
Test interaction with reflection
1 parent e8b9443 commit c4ac008

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

ext/reflection/php_reflection.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3665,10 +3665,8 @@ ZEND_METHOD(ReflectionClassConstant, getValue)
36653665
}
36663666
GET_REFLECTION_OBJECT_PTR(ref);
36673667

3668+
zval_update_constant_ex(&ref->value, ref->ce);
36683669
ZVAL_COPY_OR_DUP(return_value, &ref->value);
3669-
if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) {
3670-
zval_update_constant_ex(return_value, ref->ce);
3671-
}
36723670
}
36733671
/* }}} */
36743672

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
Handling of new in constant expressions in reflection
3+
--FILE--
4+
<?php
5+
6+
class Test1 {
7+
const A = new stdClass;
8+
}
9+
10+
$rc = new ReflectionClass(Test1::class);
11+
$rcc = $rc->getReflectionConstant('A');
12+
var_dump($rcc->getValue() === Test1::A);
13+
14+
function test1() {
15+
static $x = new stdClass;
16+
return $x;
17+
}
18+
19+
$rf = new ReflectionFunction('test1');
20+
$s = $rf->getStaticVariables();
21+
var_dump($s['x'] === test1());
22+
23+
function test2($x = new stdClass) {
24+
return $x;
25+
}
26+
27+
$rf = new ReflectionFunction('test2');
28+
$rp = $rf->getParameters()[0];
29+
// Parameter default should *not* be the same.
30+
var_dump($rp->getDefaultValue() !== test2());
31+
32+
class Test2 {
33+
public static $prop1 = new stdClass;
34+
public $prop2 = new stdClass;
35+
}
36+
37+
$rc = new ReflectionClass(Test2::class);
38+
$rp1 = $rc->getProperty('prop1');
39+
$rp2 = $rc->getProperty('prop2');
40+
// For static properties, the value should be the same,
41+
// but the default value shouldn't be.
42+
var_dump($rp1->getValue() === Test2::$prop1);
43+
// TODO: There is a pre-existing bug where the static property
44+
// default value is actually the current value without opcache.
45+
// var_dump($rp1->getDefaultValue() !== Test2::$prop1);
46+
$o = new Test2;
47+
var_dump($rp2->getValue($o) === $o->prop2);
48+
var_dump($rp2->getDefaultValue() !== $o->prop2);
49+
50+
?>
51+
--EXPECT--
52+
bool(true)
53+
bool(true)
54+
bool(true)
55+
bool(true)
56+
bool(true)
57+
bool(true)

0 commit comments

Comments
 (0)