Skip to content

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 30 commits into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d7109ac
Pull fixes from Nicolas
Girgias Jun 24, 2025
4212ed9
Pull ignores/suppressed tests from Nicolas
Girgias Jun 24, 2025
90c0a98
Use false instead of 0
Girgias Jun 24, 2025
d0834ee
IntlTestHelper::requireFullIntl() use null as second arg instead of f…
Girgias Jun 24, 2025
d387c49
Check return value of getenv()
Girgias Jun 24, 2025
ad4fd82
Symfony\Component\Validator\Constraints\Isbn does not take a bool as …
Girgias Jun 24, 2025
2ee80c5
intl false instead of null
Girgias Jun 25, 2025
6190e42
Cast result of preg_match to bool
Girgias Jun 24, 2025
9997d96
Use bool as param type
Girgias Jun 24, 2025
78f4f10
Cast bitwise op result to bool
Girgias Jun 24, 2025
de4c7d5
ErrorHandler::handleError() cast bitwise op to bool and use false ins…
Girgias Jun 24, 2025
17ab127
Yield empty string when no doc comment exists
Girgias Jun 24, 2025
f677c74
Set value to null if parse_url() fails badly and returns false
Girgias Jun 24, 2025
90401c0
Fix deprecation with PHPUnit's assertTrue
Girgias Jun 24, 2025
85de1ec
Remove ZPP test
Girgias Jun 24, 2025
72b9650
file_get_contents() does not take a fopen mode parameter
Girgias Jun 24, 2025
aa67b63
Symfony\Component\String\LazyString::resolve() add explicit string cast
Girgias Jun 24, 2025
2317f30
Fix string to true type juggling in test
Girgias Jun 24, 2025
4edbb43
Remove ZPP test
Girgias Jun 24, 2025
2017a7b
Use empty string instead of false
Girgias Jun 24, 2025
e816540
Explicit cast to bool from string
Girgias Jun 25, 2025
8afc277
Definition::addMethodCall() arg 3 must be a bool v2
Girgias Jun 25, 2025
4d883cc
Fix test passing false to ?string type
Girgias Jun 29, 2025
218a4f8
Remove ZPP tests testing false to string coercion
Girgias Jun 29, 2025
5397577
NumberFormatter::setAttribute() takes values of type int|float
Girgias Jun 29, 2025
dfcef56
Default non-existing environment variable to empty string
Girgias Jun 29, 2025
a828919
Split grapheme extraction and check if one is found
Girgias Jun 29, 2025
52dec0e
Fix substr with bool?
Girgias Jun 29, 2025
f3286e3
Use '1' instead of true
Girgias Jun 29, 2025
fa063a6
cookie_httponly key does not support values of auto
Girgias Jun 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ public function testMoney()
public function testMoneyWithoutCurrency()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType', 1234.56, [
'currency' => false,
'currency' => null,
]);

$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public static function provideObjectFieldAclCases()
return [
[null, null, null],
['object', null, 'object'],
['object', false, new FieldVote('object', false)],
['object', 0, new FieldVote('object', 0)],
['object', '', new FieldVote('object', false)],
['object', '0', new FieldVote('object', 0)],
['object', '', new FieldVote('object', '')],
['object', 'field', new FieldVote('object', 'field')],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

->setAutoconfigured(true);

$container->setAlias('twig_test', 'twig')->setPublic(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function onKernelRequest(RequestEvent $event): void
if ($mediaType = $this->getMediaType($asset->publicPath)) {
$response->headers->set('Content-Type', $mediaType);
}
$response->headers->set('X-Assets-Dev', true);
$response->headers->set('X-Assets-Dev', '1');

$event->setResponse($response);
$event->stopPropagation();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private function updateServerFromUri(array $server, string $uri): array

private function extractHost(string $uri): ?string
{
$host = parse_url($uri, \PHP_URL_HOST);
$host = parse_url($uri, \PHP_URL_HOST) ?: null;

if ($port = parse_url($uri, \PHP_URL_PORT)) {
return $host.':'.$port;
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public function testUrlDecodeParameters()

public static function provideCreateConnection(): array
{
$hosts = array_map(fn ($host) => \sprintf('host[%s]', $host), explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
$envHosts = getenv('REDIS_CLUSTER_HOSTS');
if ($envHosts === false) {
$envHosts = '';
}
$hosts = array_map(fn ($host) => \sprintf('host[%s]', $host), explode(' ', $envHosts));

return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function generateSignature(\ReflectionClass $class): iterable
yield print_r($attributes, true);
$attributes = [];

yield $class->getDocComment();
yield $class->getDocComment() ?: '';
yield (int) $class->isFinal();
yield (int) $class->isAbstract();

Expand All @@ -144,7 +144,7 @@ private function generateSignature(\ReflectionClass $class): iterable
yield print_r($attributes, true);
$attributes = [];

yield $p->getDocComment();
yield $p->getDocComment() ?: '';
yield $p->isDefault() ? '<default>' : '';
yield $p->isPublic() ? 'public' : 'protected';
yield $p->isStatic() ? 'static' : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
$setters = $value->getMethodCalls();
$value->setMethodCalls($withers);
foreach ($setters as $call) {
$value->addMethodCall($call[0], $call[1], $call[2] ?? false);
$value->addMethodCall($call[0], $call[1], isset($call[2]) && $call[2]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ private function createService(Definition $definition, array &$inlineServices, b
if (!$definition->isDeprecated() && \is_array($factory) && \is_string($factory[0])) {
$r = new \ReflectionClass($factory[0]);

if (0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
if (0 < strpos($r->getDocComment() ?: '', "\n * @deprecated ")) {
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id, $r->name);
}
}
Expand All @@ -1191,7 +1191,7 @@ private function createService(Definition $definition, array &$inlineServices, b
$service = $r->getConstructor() ? $r->newInstanceArgs($arguments) : $r->newInstance();
}

if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment() ?: '', "\n * @deprecated ")) {
trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private function collectLineage(string $class, array &$lineage): void
return;
}
$file = $r->getFileName();
if (str_ends_with($file, ') : eval()\'d code')) {
if ($file && str_ends_with($file, ') : eval()\'d code')) {
$file = substr($file, 0, strrpos($file, '(', -17));
}
if (!$file || $this->doExport($file) === $exportedFile = $this->export($file)) {
Expand Down Expand Up @@ -575,10 +575,10 @@ private function generateProxyClasses(): array
}
do {
$file = $r->getFileName();
if (str_ends_with($file, ') : eval()\'d code')) {
if ($file && str_ends_with($file, ') : eval()\'d code')) {
$file = substr($file, 0, strrpos($file, '(', -17));
}
if (is_file($file)) {
if ($file && is_file($file)) {
$this->container->addResource(new FileResource($file));
}
$r = $r->getParentClass() ?: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
}

foreach ($this->getChildren($service, 'call') as $call) {
$definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument', $file), XmlUtils::phpize($call->getAttribute('returns-clone')));
$returnClone = $call->getAttribute('returns-clone');
$definition->addMethodCall(
$call->getAttribute('method'),
$this->getArgumentsAsPhp($call, 'argument', $file),
$returnClone !== '' ? XmlUtils::phpize($returnClone) : false
);
}

$tags = $this->getChildren($service, 'tag');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function invalidDeprecationMessageProvider(): array
"With \ns" => ["invalid \n message %alias_id%"],
'With */s' => ['invalid */ message %alias_id%'],
'message not containing required %alias_id% variable' => ['this is deprecated'],
'template not containing required %alias_id% variable' => [true],
//'template not containing required %alias_id% variable' => [true],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.

🙈

{
$container = new ContainerBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static function invalidDeprecationMessageProvider(): array
"With \ns" => ["invalid \n message %service_id%"],
'With */s' => ['invalid */ message %service_id%'],
'message not containing require %service_id% variable' => ['this is deprecated'],
'template not containing require %service_id% variable' => [true],
//'template not containing require %service_id% variable' => [true],
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function resolve(string $uri, ?string $baseUri): string

// relative path
$path = parse_url(substr($baseUri, \strlen($baseUriCleaned)), \PHP_URL_PATH) ?? '';
$path = self::canonicalizePath(substr($path, 0, strrpos($path, '/')).'/'.$uri);
$path = self::canonicalizePath(substr($path, 0, strrpos($path, '/') ?: 0).'/'.$uri);

return $baseUriCleaned.('' === $path || '/' !== $path[0] ? '/' : '').$path;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ public function handleError(int $type, string $message, string $file, int $line)
$silenced = 0 === ($level & $type);
// Strong errors are not authorized to be silenced.
$level |= \E_RECOVERABLE_ERROR | \E_USER_ERROR | \E_DEPRECATED | \E_USER_DEPRECATED;
$log = $this->loggedErrors & $type;
$throw = $this->thrownErrors & $type & $level;
$log = (bool) ($this->loggedErrors & $type);
$throw = (bool) ($this->thrownErrors & $type & $level);
$type &= $level | $this->screamedErrors;

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

if (!$type || (!$log && !$throw)) {
Expand Down Expand Up @@ -472,7 +472,7 @@ public function handleError(int $type, string $message, string $file, int $line)
}

if ($this->isRecursive) {
$log = 0;
$log = false;
} else {
try {
$this->isRecursive = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function getConstructorTestData()
'1k', '1ki', '1m', '1mi', '1g', '1gi',
],
[
false, null, '',
null, '',
' ', 'foobar',
'=1', '===1',
'0 . 1', '123 .45', '234. 567',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function getTestFilterData()

$inner[] = new MockSplFileInfo([
'name' => 'unreadable-file.txt',
'contents' => false,
'contents' => '',
'type' => 'file',
'mode' => 'r+', ]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public function reverseTransform(mixed $value): ?\DateInterval

private function isISO8601(string $string): bool
{
return preg_match('/^P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string);
return (bool) preg_match('/^P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function getNumberFormatter(): \NumberFormatter
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
}

$formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->grouping);
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, (int)$this->grouping);

return $formatter;
}
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Form/Tests/ButtonBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public static function getInvalidNames()
{
return [
[''],
[false],
[null],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testTransformWithRounding($input, $output, $roundingMode)
public function testReverseTransform()
{
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);

\Locale::setDefault('de_AT');

Expand All @@ -115,7 +115,7 @@ public function testReverseTransformEmpty()
public function testReverseTransformWithGrouping()
{
// Since we test against "de_DE", we need the full implementation
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);

\Locale::setDefault('de_DE');

Expand Down Expand Up @@ -210,7 +210,7 @@ public function testReverseTransformExpectsValidNumber()
public function testReverseTransformExpectsInteger($number, $locale)
{
$this->expectException(TransformationFailedException::class);
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);

\Locale::setDefault($locale);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function tearDown(): void
public function testTransform()
{
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);

\Locale::setDefault('de_AT');

Expand Down Expand Up @@ -71,7 +71,7 @@ public function testTransformEmpty()
public function testReverseTransform()
{
// Since we test against "de_AT", we need the full implementation
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);

\Locale::setDefault('de_AT');

Expand Down Expand Up @@ -99,7 +99,7 @@ public function testReverseTransformEmpty()
public function testFloatToIntConversionMismatchOnReverseTransform()
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);
\Locale::setDefault('de_AT');

$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
Expand All @@ -108,7 +108,7 @@ public function testFloatToIntConversionMismatchOnReverseTransform()
public function testFloatToIntConversionMismatchOnTransform()
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, \NumberFormatter::ROUND_DOWN, 100);
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);
\Locale::setDefault('de_AT');

$this->assertSame('10,20', $transformer->transform(1020));
Expand All @@ -120,7 +120,7 @@ public function testValidNumericValuesWithNonDotDecimalPointCharacter()
setlocale(\LC_ALL, 'de_AT.UTF-8');

$transformer = new MoneyToLocalizedStringTransformer(4, null, null, 100);
IntlTestHelper::requireFullIntl($this, false);
IntlTestHelper::requireFullIntl($this, null);
\Locale::setDefault('de_AT');

$this->assertSame('0,0035', $transformer->transform(12 / 34));
Expand Down
Loading
Loading