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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 06:01:29 2024 UTC