forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reflection: show the name of object constants used as default properties
When a property default is based on a global constant, identify and use the name of that constant. Previously, `format_default_value()` assumed that non-scalar and non-array defaults were always going to be `IS_CONSTANT_AST` pointers, and when the AST expression had been evaluated and produced an object, depending on when the `ReflectionClass` or `ReflectionProperty` instance had been created, the default was shown as one of `callable`, `__CLASS__`, or `...`. Instead, if the default value is an object (`IS_OBJECT`), find the name of the `zend_constant` in the global `EG(zend_constants)` that points to the same value, and show that name. If no constant is found, instead of the confusing output of treating the object as an `IS_CONSTANT_AST` value, show `"<Unknown object value>"`. Add test cases for each of the `callable`, `__CLASS__`, and `...` cases to confirm that they all now properly show the name of the constant. Closes phpgh-15902
- Loading branch information
1 parent
c7397f5
commit e6683a9
Showing
7 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ext/reflection/tests/gh15902/ReflectionClass-callable.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
ReflectionClass object default property - used to say "callable" | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
define('FOO', new stdClass); | ||
|
||
new C; | ||
|
||
$reflector = new ReflectionClass(C::class); | ||
var_dump( (string)$reflector ); | ||
?> | ||
--EXPECTF-- | ||
string(%d) "Class [ <user> class C ] { | ||
@@ %sReflectionClass-callable.php %d-%d | ||
|
||
- Constants [0] { | ||
} | ||
|
||
- Static properties [0] { | ||
} | ||
|
||
- Static methods [0] { | ||
} | ||
|
||
- Properties [1] { | ||
Property [ public stdClass $a = FOO ] | ||
} | ||
|
||
- Methods [0] { | ||
} | ||
} | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
ReflectionClass object default property - used to say "__CLASS__" | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
$reflector = new ReflectionClass(C::class); | ||
|
||
define('FOO', new stdClass); | ||
new C; | ||
|
||
var_dump( (string)$reflector ); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(%d) "Class [ <user> class C ] { | ||
@@ %sReflectionClass-class.php %d-%d | ||
|
||
- Constants [0] { | ||
} | ||
|
||
- Static properties [0] { | ||
} | ||
|
||
- Static methods [0] { | ||
} | ||
|
||
- Properties [1] { | ||
Property [ public stdClass $a = FOO ] | ||
} | ||
|
||
- Methods [0] { | ||
} | ||
} | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--TEST-- | ||
ReflectionClass object default property - used to say "..." | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
$reflector = new ReflectionClass(C::class); | ||
$c = $reflector->newLazyGhost(function () {}); | ||
|
||
define('FOO', new stdClass); | ||
|
||
$c->a; | ||
|
||
var_dump( (string)$reflector ); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(%d) "Class [ <user> class C ] { | ||
@@ %sReflectionClass-dots.php %d-%d | ||
|
||
- Constants [0] { | ||
} | ||
|
||
- Static properties [0] { | ||
} | ||
|
||
- Static methods [0] { | ||
} | ||
|
||
- Properties [1] { | ||
Property [ public stdClass $a = FOO ] | ||
} | ||
|
||
- Methods [0] { | ||
} | ||
} | ||
" |
19 changes: 19 additions & 0 deletions
19
ext/reflection/tests/gh15902/ReflectionProperty-callable.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
ReflectionProperty object default - used to say "callable" | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
define('FOO', new stdClass); | ||
|
||
new C; | ||
|
||
$reflector = new ReflectionProperty(C::class, 'a'); | ||
var_dump( (string)$reflector ); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(%d) "Property [ public stdClass $a = FOO ] | ||
" |
19 changes: 19 additions & 0 deletions
19
ext/reflection/tests/gh15902/ReflectionProperty-class.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
ReflectionProperty object default - used to say "__CLASS__" | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
$reflector = new ReflectionProperty(C::class, 'a'); | ||
|
||
define('FOO', new stdClass); | ||
new C; | ||
|
||
var_dump( (string)$reflector ); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(%d) "Property [ public stdClass $a = FOO ] | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
ReflectionProperty object default - used to say "..." | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
public stdClass $a = FOO; | ||
} | ||
$reflector = new ReflectionProperty(C::class, 'a'); | ||
$lazyFactory = new ReflectionClass(C::class); | ||
$c = $lazyFactory->newLazyGhost(function () {}); | ||
|
||
define('FOO', new stdClass); | ||
|
||
$c->a; | ||
|
||
var_dump( (string)$reflector ); | ||
|
||
?> | ||
--EXPECTF-- | ||
string(%d) "Property [ public stdClass $a = FOO ] | ||
" |