Description
Symfony version(s) affected
7.2.x
Description
I know property info is trying to integrate more and more with the new now stable type-info component, slowly trying to move away from the internal type - now aliased as "legacy type" inside the codebase. However one thing has definitely changed, which for our project is a breaking change - the UnionType internally sorts the types by name:
I have no idea why this was implemented but we have quite a few cases where the order of the union type arguments is important. One big case is the deserialization process - if one property can be one of multiple types - we try to deserialize in the correct order - and which objects succeeds first - has priority. Some objects have similar structure, so order is important. The old way property info works does not sort the union types.
How to reproduce
For example the following setup:
class Car
{
public string $make;
}
class Truck
{
public string $make;
}
class Wrapper
{
/**
* @var Truck[]|Car[]
*/
public array $property;
}
Will return a union type of 2 CollectionTypes, first one will be Car, second one will be Truck. This is if we're using the new PropertyInfo->getType() method, instead of the "legacy one" PropertyInfo->getTypes().
Possible Solution
Do not sort the types inside the union type.
Additional Context
No response