Merged
Conversation
zonuexe
commented
Jan 7, 2025
| #[Inject('attribute')] | ||
| \stdClass $attribute, | ||
| ?\stdClass $typedOptionalValue = new stdClass(), | ||
| ?\stdClass $typedOptionalValueDefaultNull = null, |
Contributor
Author
There was a problem hiding this comment.
These are examples where adding ? to a type changes behavior.
Checking for both = new stdClass() and = null highlights the difference in behavior.
PHP 8.4 prohibits non-optional (mandatory) parameters from appearing after optional parameters. This commit updates various constructors and methods so that optional parameters with default values (including null or new stdClass instances) are placed at the end, ensuring compliance with the new PHP 8.4 requirements.
Contributor
Author
ok. |
Contributor
Author
|
In my environment, the tests passed with PHP 8.0, 8.3 and 8.4. The files separated due to syntax incompatibilities have the following differences: diff% diff -u tests/IntegrationTest/Definitions/Attribute/class-php83.php tests/IntegrationTest/Definitions/Attribute/class.php
--- tests/IntegrationTest/Definitions/Attribute/class-php83.php 2025-01-08 01:02:44
+++ tests/IntegrationTest/Definitions/Attribute/class.php 2025-01-08 01:02:38
@@ -40,7 +40,7 @@
\stdClass $lazyService,
#[Inject('attribute')]
\stdClass $attribute,
- \stdClass $typedOptionalValue = null,
+ ?\stdClass $typedOptionalValue = new stdClass(),
?\stdClass $typedOptionalValueDefaultNull = null,
string $optionalValue = 'hello'
) {
@@ -87,7 +87,7 @@
\stdClass $lazyService,
#[Inject('attribute')]
stdClass $attribute,
- \stdClass $typedOptionalValue = null,
+ ?\stdClass $typedOptionalValue = new stdClass,
?\stdClass $typedOptionalValueDefaultNull = null,
$optionalValue = 'hello'
) {
% diff -u tests/IntegrationTest/Definitions/CreateDefinition/class-php83.php tests/IntegrationTest/Definitions/CreateDefinition/class.php
--- tests/IntegrationTest/Definitions/CreateDefinition/class-php83.php 2025-01-08 01:06:26
+++ tests/IntegrationTest/Definitions/CreateDefinition/class.php 2025-01-08 01:05:53
@@ -25,7 +25,7 @@
string $scalarValue,
\stdClass $typedValue,
\stdClass $lazyService,
- \stdClass $typedOptionalValue = null,
+ ?\stdClass $typedOptionalValue = new \stdClass(),
?\stdClass $typedOptionalValueDefaultNull = null,
$optionalValue = 'hello'
) {
@@ -63,7 +63,7 @@
string $scalarValue,
\stdClass $typedValue,
\stdClass $lazyService,
- \stdClass $typedOptionalValue = null,
+ ?\stdClass $typedOptionalValue = new stdClass(),
?\stdClass $typedOptionalValueDefaultNull = null,
$optionalValue = 'hello'
) { |
Contributor
Author
|
The only remaining coding standard violations are in the implementation code in the |
|
Also relates to #896. |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make to ensure compatibility with PHP 8.4:
?nullable type to optional parameters.It is similar to #897, but this PR is focused only on PHP 8.4 support.