Bug #80391 [Asn->Csd]: Iterable not covariant to mixed
Edit report at https://bugs.php.net/bug.php?id=80391&edit=1
ID: 80391
Updated by: nikic@php.net
Reported by: peldax at gmail dot com
Summary: Iterable not covariant to mixed
-Status: Assigned
+Status: Closed
Type: Bug
Package: *General Issues
Operating System: All
PHP Version: 8.0.0RC5
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=912cb8b8b52f958ac6eb482466c01e99fc0c0e35
Log: Fixed bug #80391
Previous Comments:
------------------------------------------------------------------------
[2020-11-20 19:56:49] peldax at gmail dot com
Strange addition:
Contravariace works correctly, following script compiles succesfully:
<?php
interface SomeInterface {
public function getValue(iterable $arg) : void;
}
class Child implements SomeInterface
{
public function getValue(mixed $arg) : void
{
return;
}
}
------------------------------------------------------------------------
[2020-11-20 19:34:38] peldax at gmail dot com
Description:
------------
Hello,
When I declare a function in a class/interface with "mixed" return type, and than extend
the class and apply covariant return type "iterable", I get compatibility error saying
that functions are not compatible.
Code snippet bellow gives me:
Fatal error: Declaration of Child::getValue(): iterable must be compatible with
SomeInterface::getValue(): mixed
I am not sure if "iterable" has any special treatment (it works correctly for other types,
such as int, self, Child, ...) or is it just forgotten pseudo type.
Thank you.
Václav PelÃÅ¡ek @peldax
Test script:
---------------
<?php
interface SomeInterface {
public function getValue() : mixed;
}
class Child implements SomeInterface
{
public function getValue() : iterable
{
return [];
}
}
Expected result:
----------------
Script compiles successfully.
Actual result:
--------------
Fatal error: Declaration of Child::getValue(): iterable must be compatible with
SomeInterface::getValue(): mixed
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80391&edit=1
Thread (3 messages)