Skip to content

Commit 7173d6c

Browse files
committed
bug symfony#38510 [PropertyInfo] Support for the mixed type (derrabus)
This PR was merged into the 3.4 branch. Discussion ---------- [PropertyInfo] Support for the mixed type | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A In php 8, `mixed` is [a valid type declaration](https://wiki.php.net/rfc/mixed_type_v2). Running the following script on php 8… ``` use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; class MyClass { public function getA(): mixed {} } $reflection = new ReflectionExtractor(); $reflection->getTypes(MyClass::class, 'a'); ``` … causes a fatal error: ``` PHP Fatal error: Uncaught InvalidArgumentException: "mixed" is not a valid PHP type. in /path/to/symfony/src/Symfony/Component/PropertyInfo/Type.php:70 ``` This PR should fix the issue. Commits ------- 1a3b538 [PropertyInfo] Support for the mixed type.
2 parents b95ad41 + 1a3b538 commit 7173d6c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private function extractFromReflectionType(\ReflectionType $reflectionType, \Ref
243243

244244
foreach ($reflectionType instanceof \ReflectionUnionType ? $reflectionType->getTypes() : [$reflectionType] as $type) {
245245
$phpTypeOrClass = $reflectionType instanceof \ReflectionNamedType ? $reflectionType->getName() : (string) $type;
246-
if ('null' === $phpTypeOrClass) {
246+
if ('null' === $phpTypeOrClass || 'mixed' === $phpTypeOrClass) {
247247
continue;
248248
}
249249

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public function php80TypesProvider()
221221
['timeout', [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_FLOAT)]],
222222
['optional', [new Type(Type::BUILTIN_TYPE_INT, true), new Type(Type::BUILTIN_TYPE_FLOAT, true)]],
223223
['string', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Stringable'), new Type(Type::BUILTIN_TYPE_STRING)]],
224+
['payload', null],
225+
['data', null],
224226
];
225227
}
226228

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public function getOptional(): int|float|null
2323
public function setString(string|\Stringable $string)
2424
{
2525
}
26+
27+
public function setPayload(mixed $payload)
28+
{
29+
}
30+
31+
public function getData(): mixed
32+
{
33+
}
2634
}

0 commit comments

Comments
 (0)