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

fix: PHP 8.4 deprecations with implicit nullable parameters #2995

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

Jubeki
Copy link
Contributor

@Jubeki Jubeki commented Sep 4, 2024

Issue #, if available:
Not available.

Description of changes:
As of PHP 8.4 parameters marked as implicit nullable will throw a deprecation warning. Explicitly Declaring is Supported as of PHP 7.1 (See https://www.php.net/manual/en/migration71.new-features.php). This SDK requires PHP >=7.2.5 so no lower bounds need to be updated.

This PR adds the question mark or null to the parameter types to to avoid the deprecation warning in PHP 8.4.

This was done with the help of laravel/pint and the following configuration in the pint.json:

{
    "preset": "empty",
    "rules": {
        "nullable_type_declaration_for_default_null_value": true
    }
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Jubeki Jubeki changed the title Mark parameters explicit nullable PHP 8.4: Mark parameters explicit nullable Sep 9, 2024
@Jubeki Jubeki changed the title PHP 8.4: Mark parameters explicit nullable fix: PHP 8.4 deprecations with implicit nullable parameters Sep 11, 2024
@yenfryherrerafeliz
Copy link
Contributor

Hi @Jubeki, thanks for taking the time for opening this PR. While your suggestion is valid, we can not accept this change right now since it will break customers extending our SDK, and it will force them to also need to apply this change. In other words it is not a backward compatibility change.

Thanks!

@Jubeki
Copy link
Contributor Author

Jubeki commented Sep 11, 2024

Hey @yenfryherrerafeliz

the changes in this PR are fully backwards compatible and contain no breaking changes.
See the following article: https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated#change

The explicit declaration is compatible with PHP 7.1 and later, even if you extend the class.

Would you please consider opening this PR again for further review?

Thanks!

@Jubeki
Copy link
Contributor Author

Jubeki commented Sep 11, 2024

You can also take a look at the following snippet at PHP Playground at php-play.dev

<?php

class ParentClass {
   public function tester(?string $value = null) {}
}

// This class is compatible after PHP 7.1, because it keeps the null type implicitly.
class SubClass extends ParentClass {
     public function tester(string $value = null) {}
}

// This class is compatible after PHP 7.1, because it keeps the null type explicitly.
class SubClass2 {
   public function tester(?string $value) {}
}

// Fatal Error: This class is not compatible with the parent class even before PHP 8.4,
// because the implicit null type is removed from the declaration.
class SubClass3 extends ParentClass {
     public function tester(string $value) {}
}

// Fatal Error: This class is not compatible with the parent class even before PHP 8.4,
// because the implicit null type is removed from the declaration.
class SubClass4 extends ParentClass {
     public function tester(string $value = 'x') {}
}

@Jubeki
Copy link
Contributor Author

Jubeki commented Sep 23, 2024

Hey @yenfryherrerafeliz and @stobrien89,

would you be willing to take another look at this PR, given the above arguments, that this is not a breaking change, but an improvement for all upcoming PHP 8.4 installations?

Thanks!

@puzzledmonkey
Copy link

@yenfryherrerafeliz Is there any chance this can get revisited? This needs fixing to support PHP 8.4 and as @Jubeki says it should be entirely backwards-compatible.

@yenfryherrerafeliz
Copy link
Contributor

Hey @Jubeki, sorry, I think I jumped too fast in answering to this. I got biased with the fact that changing method signatures for classes will break any super class relaying on those parent classes. But in this case you are right. It is a backward compatible change. I will do another review to this as soon as possible.

Thanks!

@Jubeki
Copy link
Contributor Author

Jubeki commented Sep 30, 2024

Hey @yenfryherrerafeliz, that is fully understandable on my side. I also could have done a better job explaining something about the rfc and the backwards compatibility. I simply assumed everybody would know because I already submitted similar PRs where people already knew that this change would be okay.

Thanks!

@puzzledmonkey
Copy link

thanks @Jubeki and @yenfryherrerafeliz !

@stobrien89
Copy link
Member

Hi @Jubeki,

Sorry for the confusion— looks good to me. I added a changelog entry and we'll merge after the current CI run. Thanks for the contribution!

@stobrien89 stobrien89 merged commit ef76bf0 into aws:master Oct 1, 2024
19 checks passed
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