Skip to content

Commit ab1a02f

Browse files
committed
bug #46968 [PropertyInfo] Make sure nested composite types do not crash ReflectionExtractor (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [PropertyInfo] Make sure nested composite types do not crash ReflectionExtractor | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of #44282 | License | MIT | Doc PR | N/A A composite type like `(\Traversable&\Countable)|null` which is allowed in PHP 8.2 currently causes a fatal error in `ReflectionExtractor` because of a call to an undefined function. This PR fixes it by making `ReflectionExtractor` report that it could not extract any types. Implementing full support for composite types to the extent that PHP 8.2 supports them would not be too difficult, but it would probably not pass as a bugfix. Once this is merged up, I'll prepare a PR for the 6.2 branch implementing full support. Commits ------- f146e72 Make sure nested composite types do not crash ReflectionExtractor
2 parents ec69d4e + f146e72 commit ab1a02f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ private function extractFromReflectionType(\ReflectionType $reflectionType, \Ref
334334
$nullable = $reflectionType->allowsNull();
335335

336336
foreach (($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) ? $reflectionType->getTypes() : [$reflectionType] as $type) {
337+
if (!$type instanceof \ReflectionNamedType) {
338+
// Nested composite types are not supported yet.
339+
return [];
340+
}
341+
337342
$phpTypeOrClass = $type->getName();
338343
if ('null' === $phpTypeOrClass || 'mixed' === $phpTypeOrClass || 'never' === $phpTypeOrClass) {
339344
continue;

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ public function testExtractPhp82Type($property, array $type = null)
281281
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, []));
282282
}
283283

284-
public function php82TypesProvider()
284+
public function php82TypesProvider(): iterable
285285
{
286286
yield ['nil', null];
287287
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
288+
289+
// Nesting intersection and union types is not supported yet,
290+
// but we should make sure this kind of composite types does not crash the extractor.
291+
yield ['someCollection', null];
288292
}
289293

290294
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ class Php82Dummy
1616
public null $nil = null;
1717

1818
public false $false = false;
19+
20+
public (\Traversable&\Countable)|null $someCollection = null;
1921
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy