Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[W.I.P.] Fix implicit to and from bool type juggling#60890
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Conversation
carsonbot commentedJun 24, 2025
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
@@ -568,7 +568,7 @@ private function parseDefinition(string $id, array|string|null $service, string | |||
if (isset($call['method']) && \is_string($call['method'])) { | |||
$method = $call['method']; | |||
$args = $call['arguments'] ?? []; | |||
$returnsClone = $call['returns_clone'] ?? false; | |||
$returnsClone = $call['returns_clone'] ? true : false; |
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.
this will break ifreturns_clone
is not defined in the array.
and that's a case where we expect a boolean if the key is defined, or an undefined key (which should then default tofalse
)
@@ -307,7 +307,7 @@ public function setMethodCalls(array $calls = []): static | |||
{ | |||
$this->calls = []; | |||
foreach ($calls as $call) { | |||
$this->addMethodCall($call[0], $call[1], $call[2] ?? false); | |||
$this->addMethodCall($call[0], $call[1], $call[2] ? true : false); |
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.
this is a case where the third value in the array is expected to be a boolean or absent, which is broken in this change.
$definition->addMethodCall( | ||
$call->getAttribute('method'), | ||
$this->getArgumentsAsPhp($call, 'argument', $file), | ||
(bool) XmlUtils::phpize($call->getAttribute('returns-clone')) |
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.
I suggest doing a method handling of the case of the missing attribute (instead of handling it as$call->getAttribute('returns-clone')
returning an empty string which then casts tofalse
)
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.
Do you want me to basically just do:
(bool)XmlUtils::phpize($call->getAttribute('returns-clone')) | |
XmlUtils::phpize($call->getAttribute('returns-clone')) !=='' |
or something else? Because I don't really understand your suggestion.
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.
Doing something like$call->getAttribute('returns-clone') !== '' ? XmlUtils::phpize($call->getAttribute('returns-clone')) : false
, as we need to detect the case of the omitted attribute (to default tofalse
) while still using the proper output ofphpize
for cases using the attribute.
@@ -589,7 +589,7 @@ private function parseDefinition(string $id, array|string|null $service, string | |||
} else { | |||
$method = $call[0]; | |||
$args = $call[1] ?? []; | |||
$returnsClone = $call[2] ?? false; | |||
$returnsClone = $call[2] ? true : false; |
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.
the existing code should probably be kept here as well.
Uh oh!
There was an error while loading.Please reload this page.
Some of those changes are definitely legitimate as they are clearly mistakes in the existing code that went unnoticed (static analysis could catch them, but our CI only reportsnew violations in each PR and we never worked on fixing issues reported in existing code):
Those could definitely be submitted directly (against the 6.4 branch). We have other cases (when using preg_match or bitwise comparisons) where we indeed rely on the implicit type juggling of the return type, which are legitimate changes once PHP deprecates those type juggling rules (static analysis probably also prevents them for new code). As reported in my review comments, the changes done in the DI component look wrong to me (and are the cause of failures in the CI as well) |
Yes I had figured out the cause, but I was having some other local failures before that made it difficult to waddle through stuff. There is also a bug in master on php-src which is not helping me to get a good overview of the situation. Question about |
@@ -336,7 +336,7 @@ public function testProcessFailsOnPassingClassToScalarTypedParameter() | |||
(new CheckTypeDeclarationsPass(true))->process($container); | |||
} | |||
public functiontestProcessSuccessOnPassingBadScalarType() | |||
public functionxtestProcessSuccessOnPassingBadScalarType() |
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.
why skipping this test ?
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.
I stole this from@nicolas-grekas WIP commit:nicolas-grekas@02e3881
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.
🙈
@@ -51,7 +51,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void | |||
$container->register(StaticExtensionWithAttributes::class, StaticExtensionWithAttributes::class) | |||
->setAutoconfigured(true); | |||
$container->register(RuntimeExtensionWithAttributes::class, RuntimeExtensionWithAttributes::class) | |||
->setArguments(['prefix_']) | |||
->setArguments([true]) |
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.
given thatRuntimeExtensionWithAttributes
performs string concatenation with the prefix, the right fix is rather to change the constructor argument type in this RuntimeExtensionWithAttributes stub class.
Uh oh!
There was an error while loading.Please reload this page.
Not sure what those asserts are doing however
There is no need to test false as this is a PHP engine behaviour to cast to empty string
There is no need to test false as this is a PHP engine behaviour to cast to empty string
@@ -307,7 +307,7 @@ public function setMethodCalls(array $calls = []): static | |||
{ | |||
$this->calls = []; | |||
foreach ($calls as $call) { | |||
$this->addMethodCall($call[0], $call[1], $call[2] ?? false); | |||
$this->addMethodCall($call[0], $call[1],isset($call[2]) && $call[2]); |
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.
Do you have stack trace for the case triggering the deprecation here (without your patch) ? Maybe we have some tests not using the expected structure for the array, but it might be better to fix the root cause instead of a symptom (replacing the boolean type juggling in function context by a boolean type juggling in boolean operator context, which is not deprecated)
$definition->addMethodCall( | ||
$call->getAttribute('method'), | ||
$this->getArgumentsAsPhp($call, 'argument', $file), | ||
(bool) XmlUtils::phpize($call->getAttribute('returns-clone')) |
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.
Doing something like$call->getAttribute('returns-clone') !== '' ? XmlUtils::phpize($call->getAttribute('returns-clone')) : false
, as we need to detect the case of the omitted attribute (to default tofalse
) while still using the proper output ofphpize
for cases using the attribute.
@@ -589,7 +589,7 @@ private function parseDefinition(string $id, array|string|null $service, string | |||
} else { | |||
$method = $call[0]; | |||
$args = $call[1] ?? []; | |||
$returnsClone = $call[2] ?? false; | |||
$returnsClone =isset($call[2]) && $call[2]; |
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.
Same for those 2 cases. My expectation here is that we always expected a boolean Yaml value (or nothing) in such case, which would not trigger the deprecation with the existing code.
If we have some tests using non-boolean values, we might want to fix those tests instead (and maybe trigger a deprecation in Symfony for projects using a non-boolean value).
@@ -65,7 +65,7 @@ public static function provideTransformations() | |||
public function testTransform($from, $to, $locale) | |||
{ | |||
// Since we test against other locales, we need the full implementation | |||
IntlTestHelper::requireFullIntl($this,false); | |||
IntlTestHelper::requireFullIntl($this,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.
I suggest omittingnull
entirely as it is optional (as done in some of the impacted files btw).
Uh oh!
There was an error while loading.Please reload this page.
This is to see part of the impact ofphp/php-src#18879, and it seems to be finding some bugs in tests or SF itself, but I would need confirmation from other people.
This is very much W.I.P. and I might use CI to check that my changes are correct as I have some local test failures even just running with 8.4.8
I am well aware the commit messages are kinda useless at the moment, but they are somewhat self-contained, so they can be looked at individually.