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

Is there a rule to convert implicitly nullable types to explict ones? #8520

Closed
mfn opened this issue Mar 3, 2024 · 8 comments · Fixed by rectorphp/rector-src#5724
Closed
Labels

Comments

@mfn
Copy link
Contributor

mfn commented Mar 3, 2024

Question

I learned about this via sebastianbergmann/phpunit#5719 which references https://wiki.php.net/rfc/deprecate-implicitly-nullable-types , and I was wondering if per chance there is already a rule covering this?

I went through all of them but couldn't find one where I had the feeling it was the correct one; but maybe I searched for the wrong keywords (nullable, implicitly).

Thanks

@samsonasik
Copy link
Member

That seems php 8.4 rfc, so I think we can wait until that got merged to master branch of php-src so we can add to PhpVersionFeature, also need to verify if that cause signature bc break.

@sebastianbergmann
Copy link

sebastianbergmann commented Mar 3, 2024

also need to verify if that cause signature bc break

It does not:

<?php declare(strict_types=1);
interface I
{
    public function m(?string $a = null): void;
}

class C implements I
{
    public function m(string $a = null): void
    {
    }
}

As you can see here, the above does not trigger a signature incompatibility error. This is because both ?string $a = null and string $a = null declare a nullable parameter, the former explicitly, the latter implicitly.

@samsonasik
Copy link
Member

@sebastianbergmann thank you for verify 👍

@mfn
Copy link
Contributor Author

mfn commented Mar 14, 2024

RFC was accepted https://externals.io/message/122534#122632

@samsonasik
Copy link
Member

@staabm
Copy link
Contributor

staabm commented Mar 15, 2024

fwiw, I think this is already possible with PHP CS-Fixer and maybe ECS. not sure we need it also in rector.

@samsonasik
Copy link
Member

@staabm let make it possible with rector as well 👍

@mfn
Copy link
Contributor Author

mfn commented Mar 15, 2024

Nice, thank you 🙇🏼

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

Successfully merging a pull request may close this issue.

4 participants