Skip to content
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

Commits on Apr 22, 2022

  1. Fix php#8232 - always reference classes in var_export() via their FQCN

    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
    Ocramius authored and iluuu1994 committed Apr 22, 2022
    Configuration menu
    Copy the full SHA
    fd6228e View commit details
    Browse the repository at this point in the history