Bug #79840 [Opn->Nab]: Union Type in argument reports types swapped in error message
| From: | nikic@php.net | Date: | Sun, 12 Jul 2020 14:36:12 +0000 |
| Subject: | Bug #79840 [Opn->Nab]: Union Type in argument reports types swapped in error message | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227979@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79840&edit=1
ID: 79840
Updated by: nikic@php.net
Reported by: carusogabriel@php.net
Summary: Union Type in argument reports types swapped in
error message
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Any
PHP Version: master-Git-2020-07-12 (Git)
Block user comment: N
Private report: N
New Comment:
https://wiki.php.net/rfc/union_types_v2#reflection.
Also applies to error messages or anything else introspecting the type.
Previous Comments:
------------------------------------------------------------------------
[2020-07-12 14:19:58] carusogabriel@php.net
Expected and Actual results are swapped but shouldn't be, sorry
------------------------------------------------------------------------
[2020-07-12 14:17:52] carusogabriel@php.net
Description:
------------
Playing around with PHP 8, I found something in Union Type's error messages, specific in typed
arguments: the types are report in a different position from where they were declared.
Test script:
---------------
<?php
class ValidMagicMethods {
public function myMethod(string $name, array $arguments): mixed {}
}
final class NarrowedReturnType extends ValidMagicMethods {
public function myMethod(string|array $name, bool $arguments): string|float|null {}
}
Expected result:
----------------
Fatal error: Declaration of NarrowedReturnType::myMethod(array|string $name, bool $arguments):
string|float|null must be compatible with ValidMagicMethods::myMethod(string $name, array
$arguments): mixed in /in/WE96o on line 8
Actual result:
--------------
Fatal error: Declaration of NarrowedReturnType::myMethod(string|array $name, bool $arguments):
string|float|null must be compatible with ValidMagicMethods::myMethod(string $name, array
$arguments): mixed in /in/WE96o on line 8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79840&edit=1