-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
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 |
52d28ad
to
4f5a3b0
Compare
👍 |
@Ocramius Are you planning on starting a discussion on the mailing list? |
Nay, already got enough to do 😁 |
Ok, I'll send one (but proposing for |
As mentioned in https://externals.io/message/117466#117532, this will go to PHP 8.2. |
4f5a3b0
to
09db6c8
Compare
89ecffd
to
46d9157
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
46d9157
to
fd6228e
Compare
Thanks @iluuu1994! |
This PR was merged into the 4.4 branch. Discussion ---------- Fix dumping enums on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows php/php-src#8233 Makes the CI green again on PHP 8.2. Replaces #46160 Commits ------- 4244aa8 Fix dumping enums on PHP 8.2
This fix corrects a behavior of
var_export()
that was mostly "hidden" until PHP 8.1 introduced:enum
sSince
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