php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79840 Union Type in argument reports types swapped in error message
Submitted: 2020-07-12 14:17 UTC Modified: 2020-07-12 14:36 UTC
From: carusogabriel@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: master-Git-2020-07-12 (Git) OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: carusogabriel@php.net
New email:
PHP Version: OS:

 

 [2020-07-12 14:17 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-12 14:19 UTC] carusogabriel@php.net
Expected and Actual results are swapped but shouldn't be, sorry
 [2020-07-12 14:36 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-07-12 14:36 UTC] nikic@php.net
https://wiki.php.net/rfc/union_types_v2#reflection. Also applies to error messages or anything else introspecting the type.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC