|
| 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