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

Rule nullable_type_declaration_for_default_null_value should remove default value on non-optional arguments #7787

Open
nicolas-grekas opened this issue Jan 30, 2024 · 6 comments

Comments

@nicolas-grekas
Copy link

Bug report

When I applied this rule to the Symfony codebase, everything worked really well except for non-optional arguments with a null default.

For those, I had to patch them manually, see
symfony/symfony@fb9fa26

This means that in the context of https://wiki.php.net/rfc/deprecate-implicitly-nullable-types, php-cs-fixer is currently not totally safe to prepare a codebase to PHP 9. (The reason being that non-optional arguments with default values are also deprecated).

nullable_type_declaration_for_default_null_value should remove those non-optional arguments with a null default, so that upgrading is made super easy.

Runtime version

latest

Used command

php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value

@kubawerlos
Copy link
Contributor

@nicolas-grekas do you mean that nullable_type_declaration_for_default_null_value should do, what currently no_unreachable_default_argument_value does?

@nicolas-grekas
Copy link
Author

Something like that yes, but specific to null defaults. Because otherwise nullable_type_declaration_for_default_null_value is not safe since it will generate code that will trigger new deprecations, see https://3v4l.org/nSpos

@nicolas-grekas
Copy link
Author

I also posted php/php-src#13353

@nicolas-grekas
Copy link
Author

nicolas-grekas commented Feb 8, 2024

From the end user pov, the current behavior is risky because it turns
a non-deprecated syntax: (int $a = null, $b)
into a deprecated one: (?int $a = null, $b).

@SVGAnimate
Copy link

@nicolas-grekas I believe in the example below there is an update to present.

PHP 5PHP 7PHP 8
<?php
function ($a = null, $b) {
}
function (?$a, $b) {
}
<?php
function (int $a = null, $b) {
}
function (?int $a, $b) {
}

In PHP5 nullable parameter is supported thusfunction foo($a = null, $b){}
In PHP7 the nullable parameter is a mixed type ( union of int|float|string|array|object|null )
In PHP8 nullable parameter is supported thus function foo(?$a, $b){}

Copy link

github-actions bot commented May 9, 2024

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

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