Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Open
Girgias wants to merge22 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromGirgias:bool-type-juggling

Conversation

Girgias
Copy link

@GirgiasGirgias commentedJun 24, 2025
edited
Loading

QA
Branch?7.4 (but can rebase to lower)
Bug fix?maybe
New feature?no
Deprecations?no
IssuesN/A
LicenseMIT

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.

@carsonbot
Copy link

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;
Copy link
Member

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);
Copy link
Member

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'))
Copy link
Member

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)

Copy link
Author

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:

Suggested change
(bool)XmlUtils::phpize($call->getAttribute('returns-clone'))
XmlUtils::phpize($call->getAttribute('returns-clone')) !==''

or something else? Because I don't really understand your suggestion.

Copy link
Member

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;
Copy link
Member

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.

@stof
Copy link
Member

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):

  • the wrong parameter passed in the instantiation ofIsbn
  • the wrong type passed toIntlTestHelper
  • the wrong type passed tostream_set_blocking
  • the wrong parameter type in the internal method of GraphvizDumper

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 we will want to support PHP 8.5 in the 6.4 branch, fixes for them should also be submitted against 6.4 (I would suggest separating them from the ones fixing clear mistakes).

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)

@Girgias
Copy link
Author

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):

* the wrong parameter passed in the instantiation of `Isbn`* the wrong type passed to `IntlTestHelper`* the wrong type passed to `stream_set_blocking`* the wrong parameter type in the internal method of GraphvizDumper

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 we will want to support PHP 8.5 in the 6.4 branch, fixes for them should also be submitted against 6.4 (I would suggest separating them from the ones fixing clear mistakes).

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 aboutIsbn should I drop thenull argument as it's the default or not?

@GirgiasGirgias marked this pull request as ready for reviewJune 24, 2025 13:35
@carsonbotcarsonbot added this to the7.4 milestoneJun 24, 2025
@symfonysymfony deleted a comment fromcarsonbotJun 24, 2025
@symfonysymfony deleted a comment fromcarsonbotJun 24, 2025
@@ -336,7 +336,7 @@ public function testProcessFailsOnPassingClassToScalarTypedParameter()
(new CheckTypeDeclarationsPass(true))->process($container);
}

public functiontestProcessSuccessOnPassingBadScalarType()
public functionxtestProcessSuccessOnPassingBadScalarType()
Copy link
Member

Choose a reason for hiding this comment

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

why skipping this test ?

Copy link
Author

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

Choose a reason for hiding this comment

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

🙈

OskarStark reacted with laugh emoji
@@ -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])
Copy link
Member

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.

@@ -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]);
Copy link
Member

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'))
Copy link
Member

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];
Copy link
Member

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);
Copy link
Member

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).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@lyrixxlyrixxAwaiting requested review from lyrixxlyrixx is a code owner

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

@kbondkbondAwaiting requested review from kbondkbond is a code owner

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

4 participants
@Girgias@carsonbot@stof@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp