Skip to content

Make nullable parameter types explicit #34

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

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Make nullable parameter types explicit #34

merged 1 commit into from
Mar 15, 2024

Conversation

derrabus
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets N/A
Documentation N/A
License MIT

What's in this PR?

This PR turns implicit nullable parameter types to explicit ones.

Why?

PHP allows to implicitly declare a nullable parameter type by setting the parameter's default value to null. However, in PHP 8.4 this syntax has been deprecated.

https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for looking into this. some questions in code comments

@@ -1,5 +1,9 @@
# Change Log

## 1.3.1 - unreleased

- Made nullable parameter types explicit (PHP 8.4 compatibility)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to be a BC break of PHP 8.4, or only become deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 8.4 triggers a E_DEPRECATED error when it loads a file with this kind of parameter type declaration.

@@ -41,7 +41,7 @@ interface Promise
*
* @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*/
public function then(callable $onFulfilled = null, callable $onRejected = null);
public function then(?callable $onFulfilled = null, ?callable $onRejected = null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik this is a BC break for anything implementing the promise, right?

if it is, we should bump the major version number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the code is 100% equivalent. This has always been a nullable type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example where I examine the type with reflection:

https://3v4l.org/EQimk

One parameter is declared callable, the other ?callable. As you can see in the output, both parameters look the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. i also added a class that implements the interface and changes ?
at least up to 8.3 this is indeed equivalent.

thanks for the clarification, then we can savely merge this.

@dbu dbu merged commit 5caa0bc into php-http:1.x Mar 15, 2024
10 checks passed
@dbu
Copy link
Contributor

dbu commented Mar 15, 2024

https://github.com/php-http/promise/releases/tag/1.3.1

@derrabus derrabus deleted the bugfix/implicit-nullable branch March 15, 2024 13:56
@derrabus
Copy link
Contributor Author

Thank you!

@Ndiritu
Copy link
Contributor

Ndiritu commented Apr 11, 2025

@dbu, would you be open to me porting the same fix to the 1.2.x release? We're blocked on the same issue.

@xabbuh
Copy link
Member

xabbuh commented Apr 11, 2025

@Ndiritu Is there anything in 1.3.x that is blocking from updating to it but rather stay on 1.2.x instead?

@Ndiritu
Copy link
Contributor

Ndiritu commented Apr 11, 2025

@xabbuh 1.3.x deprecated generic annotations which our library depends on. Stable support for generics would help us upgrade.

@dbu
Copy link
Contributor

dbu commented Apr 14, 2025

deprecating means it will be removed in the next major version. we aim to not do any BC breaks in minor versions.

a deprecation is a warning, not an error. if you have your CI report them, configure it to accept those deprecations for now to be able to use the latest version.

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.

4 participants