Bug #81593 [NEW]: ReflectionUnionType does not honor order of type

From: Date: Fri, 05 Nov 2021 22:37:06 +0000
Subject: Bug #81593 [NEW]: ReflectionUnionType does not honor order of type
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237574@lists.php.net to get a copy of this message
From:             php at vxvr dot de
Operating system: unix / debian
PHP version:      8.1.0RC5
Package:          Reflection related
Bug Type:         Bug
Bug description:ReflectionUnionType does not honor order of type

Description:
------------
Using the latest PHP version 8.1 RC 5

I would expect the ParameterUnionType to return the ReflectionNamedTypes
in order in which they are defined at the method, but as it seems they
are returned in a fixed order.

Test script:
---------------
<?php

class MyClass {
    public function __construct(int|string $value)
    {
    }
}

$reflectionMethod = new ReflectionMethod(MyClass::class,
'__construct');
$parameterUnionType = $reflectionMethod->getParameters()[0]->getType();
$types = array_map(fn(ReflectionNamedType $type) => $type->getName(),
$parameterUnionType->getTypes());
// Expected: ['int', 'string']
// Actual: ['string', 'int']


Expected result:
----------------
// Expected: ['int', 'string']

Actual result:
--------------
// Actual: ['string', 'int']

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81593&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81593&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81593&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81593&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81593&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81593&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81593&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81593&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81593&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81593&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81593&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81593&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81593&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81593&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81593&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81593&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81593&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81593&r=mysqlcfg


Thread (2 messages)

« previous php.bugs (#237574) next »