mirror of
https://github.com/php/php-src.git
synced 2026-03-29 03:32:20 +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
28 lines
512 B
PHP
28 lines
512 B
PHP
--TEST--
|
|
Bug #73350 (Exception::__toString() cause circular references)
|
|
--FILE--
|
|
<?php
|
|
$e = new Exception();
|
|
|
|
// This line cause problem :(
|
|
// Comment it to see the difference.
|
|
(string) $e;
|
|
|
|
// This line show the clue (PHP Warning: ...).
|
|
var_export($e);
|
|
?>
|
|
--EXPECTF--
|
|
\Exception::__set_state(array(
|
|
'message' => '',
|
|
'string' => 'Exception in %sbug73350.php:%d
|
|
Stack trace:
|
|
#0 {main}',
|
|
'code' => 0,
|
|
'file' => '%sbug73350.php',
|
|
'line' => %d,
|
|
'trace' =>
|
|
array (
|
|
),
|
|
'previous' => NULL,
|
|
))
|