bug #40160 [PropertyInfo] fix extracting mixed type-hinted property types (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[PropertyInfo] fix extracting mixed type-hinted property types

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39947
| License       | MIT
| Doc PR        |

Commits
-------

be6432ee4c fix extracting mixed type-hinted property types
This commit is contained in:
Fabien Potencier 2021-02-14 11:36:42 +01:00
commit 4a32fd0446
3 changed files with 5 additions and 2 deletions

View File

@ -162,8 +162,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
try {
$reflectionProperty = new \ReflectionProperty($class, $property);
$type = $reflectionProperty->getType();
if (null !== $type) {
return $this->extractFromReflectionType($type, $reflectionProperty->getDeclaringClass());
if (null !== $type && $types = $this->extractFromReflectionType($type, $reflectionProperty->getDeclaringClass())) {
return $types;
}
} catch (\ReflectionException $e) {
// noop

View File

@ -239,6 +239,7 @@ class ReflectionExtractorTest extends TestCase
['string', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Stringable'), new Type(Type::BUILTIN_TYPE_STRING)]],
['payload', null],
['data', null],
['mixedProperty', null],
];
}

View File

@ -4,6 +4,8 @@ namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
class Php80Dummy
{
public mixed $mixedProperty;
public function getFoo(): array|null
{
}