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 override __construct from interface on NewInInitializerRector #1913

Merged

Conversation

samsonasik
Copy link
Member

Continue of #1740, given the following code:

interface OverrideInterfaceMethod
{
    public function __construct(
        ?DateTime $dateTime = null
    );
}

class SkipOverrideInterfaceMethod implements OverrideInterfaceMethod
{
    private DateTime $dateTime;

    public function __construct(
        ?DateTime $dateTime = null
    ) {
        $this->dateTime = $dateTime ?? new DateTime('now');
    }
}

got result:

-    private DateTime $dateTime;
-
-    public function __construct(
-        ?DateTime $dateTime = null
-    ) {
-        $this->dateTime = $dateTime ?? new DateTime('now');
+    public function __construct(private DateTime $dateTime = new DateTime('now'))
+    {

which cause fatal error:

Fatal error: Declaration of SkipOverrideInterfaceMethod::__construct(DateTime $dateTime = <expression>) must be compatible with OverrideInterfaceMethod::__construct(?DateTime $dateTime = null)

ref https://3v4l.org/AiBL5

@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 dbdcaa1 into main Mar 7, 2022
@TomasVotruba TomasVotruba deleted the skip-override-interface-method-new-in-initializer branch March 7, 2022 18:48
@TomasVotruba
Copy link
Member

TomasVotruba commented Mar 7, 2022

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