Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: 7.4
Choose a base branch
from

Conversation

Girgias
Copy link

@Girgias Girgias commented Jun 24, 2025

Q A
Branch? 7.4 (but can rebase to lower)
Bug fix? maybe
New feature? no
Deprecations? no
Issues N/A
License MIT

This is to see part of the impact of php/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 if returns_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 to false)

@@ -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 to false)

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

@@ -402,7 +402,7 @@ public function handleError(int $type, string $message, string $file, int $line)

// Never throw on warnings triggered by assert()
if (\E_WARNING === $type && 'a' === $message[0] && 0 === strncmp($message, 'assert(): ', 10)) {
$throw = 0;
$throw = false;
Copy link
Member

Choose a reason for hiding this comment

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

$throw is still an int if we don't enter this if branch, as it is defined with bitwise comparisons on line 400. It needs to be fixed there as well.

@stof
Copy link
Member

stof commented Jun 24, 2025

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 reports new 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)

@Girgias
Copy link
Author

Girgias commented Jun 24, 2025

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 reports new 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 about Isbn should I drop the null argument as it's the default or not?

@carsonbot carsonbot closed this Jun 24, 2025
@Girgias Girgias force-pushed the bool-type-juggling branch from d89795e to b812e26 Compare June 24, 2025 13:33
@Girgias Girgias marked this pull request as ready for review June 24, 2025 13:35
@carsonbot carsonbot added this to the 7.4 milestone Jun 24, 2025
@symfony symfony deleted a comment from carsonbot Jun 24, 2025
@symfony symfony deleted a comment from carsonbot Jun 24, 2025
@@ -336,7 +336,7 @@ public function testProcessFailsOnPassingClassToScalarTypedParameter()
(new CheckTypeDeclarationsPass(true))->process($container);
}

public function testProcessSuccessOnPassingBadScalarType()
public function xtestProcessSuccessOnPassingBadScalarType()
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

Copy link
Member

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

Choose a reason for hiding this comment

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

given that RuntimeExtensionWithAttributes performs string concatenation with the prefix, the right fix is rather to change the constructor argument type in this RuntimeExtensionWithAttributes stub class.

@@ -76,7 +76,8 @@ final public static function isStringable(mixed $value): bool
*/
final public static function resolve(\Stringable|string|int|float|bool $value): string
{
return $value;
// TODO Do something more useful for false and true?
Copy link
Member

Choose a reason for hiding this comment

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

the TODO should be removed, as a string cast is also what we do in fromStringable

@Girgias Girgias force-pushed the bool-type-juggling branch from b812e26 to a249be4 Compare June 25, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants