New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #8232 - always reference classes in var_export() via their FQCN
#8233
base: PHP-8.1
Are you sure you want to change the base?
Fix #8232 - always reference classes in var_export() via their FQCN
#8233
Conversation
|
Related. doctrine/orm#9371 IMO this change is too controversial for a patch for sure. EDIT: Just adding the EDIT 2: IN any case, you might want to see what the mailing list thinks about this change. |
1e45b50
to
8e0a680
Compare
|
Nothing controversial about it: |
|
Note: a userland fix is not viable, because values need to be referenced via FQCN even in nested structures like: |
8e0a680
to
a53ad90
Compare
|
Well, poop. @JetBrains seems to drop all whitespace on commit (even after I disabled all the tooling around it). Guess editing from plaintext editor it is :D |
|
@Ocramius You can revert all test changes and run the tests with |
|
Can't run tests locally due to https://bugs.php.net/bug.php?id=80585 - manual editing required for now. |
|
@Ocramius to me it also looks quite controversial. Especially that Also found another related issue: doctrine/orm#9371 |
a53ad90
to
8b12af4
Compare
Different use-cases, no intended consistency across the two. |
8b12af4
to
bca7f7f
Compare
…ort()` docs `var_export()` needs to prefix classes it references with `\`, because its code could be transplanted in any source location/namespace, so the assumption of it being used only in the context of the root namespace is not sufficient. For example, in a code snippet like following ( https://3v4l.org/4mONc ): ```php <?php class SomeObject {} var_export([new SomeObject]); ``` This should produce: ``` array ( 0 => \SomeObject::__set_state(array( )), ) ``` Userland should not concern itself with the contents of the `var_export()`-produced code snippets, and use them as-is instead. Ref: php/php-src#8232 Ref: php/php-src#8233 Ref: Ocramius/ProxyManager#754
|
Since I never (ever) read PHP docs, I went there and checked for the ancient bug found by @IonBazan, and went to actually fix the problem at its root there too. Docs PR is therefore at php/doc-en#1472 Also: holy crap, people post-processing |
b517e42
to
52d28ad
Compare
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: php#8232
Ref: Ocramius/ProxyManager#754
52d28ad
to
4f5a3b0
Compare
|

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

This fix corrects a behavior of
var_export()that was mostly "hidden" until PHP 8.1 introduced:enumsSince
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:
produces:
This code snippet is invalid, because
Example\MyNamespace\Foo::__set_state()(whichdoes not exist) is called.
With this patch applied, the code looks like following (valid):
Fixes #8232
Ref: Ocramius/ProxyManager#754