You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When an interface extends multiple parent interfaces, the order of extends statements affects variance compatibility parsing #25759
Fatal error: Declaration of HasOptionalValue::getValue(): ?int must be compatible with HasValue::getValue(): int
When you invert the order of the extends statements like this:
<?phpinterface Result extends HasValue, HasOptionalValue {
}
The code parses without problems.
So basically, the most restrictive interface needs to go first.
I couldn't find anything in the documentation that mentions of order of statements, so I would consider this a bug.
My expected behaviour would be that of the second example: the child interface is considered to have the smallest intersection of the two interfaces.
By the way: adding the most restrictive function declaration to the child interface will also fix the problem, but this is not always desirable as it complicates changes to the parent interface.
PHP Version
phpinfo()
PHP Version => 8.6.0
System => Linux ip-172-31-20-248.eu-central-1.compute.internal 6.1.188-233.393.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Oct 6 20:31:38 UTC 2026 x86_64
Build Date => Nov 20 2026 13:54:37
Build System => Linux ip-172-31-21-217.eu-central-1.compute.internal 6.1.166-197.305.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Mar 23 09:53:26 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Configure Command => './configure' '--with-libdir=lib64' '--without-libxml' '--disable-dom' '--disable-xml' '--disable-xmlreader' '--disable-xmlwriter' '--without-pear' '--without-openssl' '--disable-simplexml' '--without-sqlite3' '--without-pdo-sqlite' '--enable-fpm' '--enable-calendar' '--with-pecl' '--without-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--enable-intl' '--with-mcrypt' '--with-libmbfl' '--enable-ftp' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--enable-zip' '--with-zip' '--with-gettext' '--without-fileinfo' '--enable-opcache' '--with-ldap=shared' '--with-config-file-path=/home/phpversions/etc/php.8/' '--with-config-file-scan-dir=/home/phpversions/etc/php.d/' '--prefix=/home/phpversions/php/8.6.0'
Server API => Command Line Interface
In this case, the CatOwner interface needs to have the PersonWithCat interface first, or the error occurs.
This is not exactly a high priority issue, as it is an edge-case and has several workarounds, but the fact this codestyler exists tells me this is not expected behaviour.
Activity
DanielEScherzer commentedon Nov 26, 2026
This has been the case since PHP 7.1 when https://wiki.php.net/rfc/nullable_types was implemented
Compare https://3v4l.org/lFKpJ#veol with https://3v4l.org/g6AfC#veol
bitwise-operators commentedon Nov 26, 2026
Yeah, it's not exactly a common issue.
It also applies to tightening of interfaces by specifying child classes (not just nullability)
The situation where I encountered it actually looked more like this:
In this case, the
CatOwnerinterface needs to have thePersonWithCatinterface first, or the error occurs.This is not exactly a high priority issue, as it is an edge-case and has several workarounds, but the fact this codestyler exists tells me this is not expected behaviour.
Fix phpGH-25759: Make interface method variance order independent