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

[Php81] Skip dynamic class on NewInInitializerRector #1736

Merged
merged 6 commits into from
Jan 27, 2022

Conversation

samsonasik
Copy link
Member

Given the following class:

class SkipDynamicNew
{
    private object $stdClass;

    public function __construct(
        string $fallbackClass,
        ?stdClass $stdClass = null
    ) {
        $this->stdClass = $stdClass ?? new $fallbackClass;
    }
}

it produce:

-    private object $stdClass;
-
-    public function __construct(
-        string $fallbackClass,
-        ?stdClass $stdClass = null
-    ) {
-        $this->stdClass = $stdClass ?? new $fallbackClass;
+    public function __construct(string $fallbackClass, private stdClass $stdClass = new $fallbackClass)
+    {
     }

which invalid and cause error:

Fatal error: Cannot use dynamic class name in constant expression

ref https://3v4l.org/RVfne#v8.1.2

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba TomasVotruba merged commit a734965 into main Jan 27, 2022
@TomasVotruba TomasVotruba deleted the skip-dynamic-class-new-in branch January 27, 2022 12:28
@TomasVotruba
Copy link
Member

Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants