Bug #80391 [NEW]: Iterable not covariant to mixed
From: peldax at gmail dot com
Operating system: All
PHP version: 8.0.0RC5
Package: *General Issues
Bug Type: Bug
Bug description:Iterable not covariant to mixed
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 bug report at https://bugs.php.net/bug.php?id=80391&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80391&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80391&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80391&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80391&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80391&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80391&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80391&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80391&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80391&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80391&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80391&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80391&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80391&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80391&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80391&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80391&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80391&r=mysqlcfg
Thread (3 messages)
- peldax at gmail dot com