-
-
Notifications
You must be signed in to change notification settings - Fork 328
Fix tests for PHP 8.4 #898
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
Conversation
\stdClass $lazyService, | ||
#[Inject('attribute')] | ||
\stdClass $attribute, | ||
?\stdClass $typedOptionalValue = new stdClass(), | ||
?\stdClass $typedOptionalValueDefaultNull = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
ok. |
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'
) { |
The only remaining coding standard violations are in the implementation code in the
|
Also relates to #896. |
Thanks! |
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.