mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

Closes GH-8233 This fix corrects a behavior of `var_export()` that was mostly "hidden" until PHP 8.1 introduced: * properties with object initializers * constants containing object references * default values of class properties containing `enum`s Since `var_export(..., true)` is mostly used in conjunction with code generation, and we cannot make assumptions about the generated code being placed in the root namespace, we must always provide the FQCN of a class in exported code. For example: ```php <?php namespace MyNamespace { class Foo {} } namespace { echo "<?php\n\nnamespace Example;\n\n" . var_export(new \MyNamespace\Foo(), true) . ';'; } ``` produces: ```php <?php namespace Example; MyNamespace\Foo::__set_state(array( )); ``` This code snippet is invalid, because `Example\MyNamespace\Foo::__set_state()` (which does not exist) is called. With this patch applied, the code looks like following (valid): ```php <?php namespace Example; \MyNamespace\Foo::__set_state(array( )); ``` Ref: https://github.com/php/php-src/issues/8232 Ref: https://github.com/Ocramius/ProxyManager/issues/754 Ref: https://externals.io/message/117466
45 lines
843 B
PHP
45 lines
843 B
PHP
--TEST--
|
|
A SensitiveParameterValue keeps the inner value secret.
|
|
--FILE--
|
|
<?php
|
|
|
|
$v = new SensitiveParameterValue('secret');
|
|
|
|
echo "# var_dump() / debug_zval_dump() / print_r()", PHP_EOL;
|
|
var_dump($v);
|
|
debug_zval_dump($v);
|
|
print_r($v);
|
|
echo PHP_EOL;
|
|
|
|
echo "# var_export()", PHP_EOL;
|
|
echo var_export($v, true), PHP_EOL;
|
|
echo PHP_EOL;
|
|
|
|
echo "# (array) / json_encode()", PHP_EOL;
|
|
var_dump((array)$v);
|
|
var_dump(json_encode($v));
|
|
echo PHP_EOL;
|
|
|
|
echo "# ->getValue()", PHP_EOL;
|
|
var_dump($v->getValue());
|
|
|
|
?>
|
|
--EXPECTF--
|
|
# var_dump() / debug_zval_dump() / print_r()
|
|
object(SensitiveParameterValue)#%d (0) {
|
|
}
|
|
object(SensitiveParameterValue)#%d (%d) refcount(%d){
|
|
}
|
|
SensitiveParameterValue Object
|
|
|
|
# var_export()
|
|
\SensitiveParameterValue::__set_state(array(
|
|
))
|
|
|
|
# (array) / json_encode()
|
|
array(0) {
|
|
}
|
|
string(2) "{}"
|
|
|
|
# ->getValue()
|
|
string(6) "secret"
|