<?php
declare(strict_types=1);
class A {}
class B extends A {}
class C extends B {}
interface InterfaceTest { public function foo(): B; }
abstract class AbstractTest {
public abstract function foo(): B;
}
class TestAbstractCovariance extends AbstractTest {
public function foo(): C {}
}
class TestInterfaceContravariance implements InterfaceTest
{
public function foo(): A {}
}
class TestInterfaceCovariance implements InterfaceTest {
public function foo(): C {}
}
Fatal error: Declaration of TestInterfaceContravariance::foo(): A must be compatible with InterfaceTest::foo(): B in /in/01dH3 on line 19
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Fatal error: Declaration of TestInterfaceContravariance::foo(): A must be compatible with InterfaceTest::foo(): B in /in/01dH3 on line 19
Process exited with code 255.
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33
Fatal error: Declaration of TestAbstractCovariance::foo(): C must be compatible with AbstractTest::foo(): B in /in/01dH3 on line 16
Process exited with code 255.
Warning: Unsupported declare 'strict_types' in /in/01dH3 on line 3
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/01dH3 on line 9
Process exited with code 255.