Mixed Compatibility

<?php

class x           { function foo(int $a, int ...$args) {} }
class y extends x { function foo(        int ...$args) {} }  // OK!
//class z extends x { function foo(int $a, int $b, int ...$args) {} } // KO

class x2            { function foo() {} }
class y2 extends x2 { function foo(mixed ...$args) {} }  // OK!
//class y22 extends x2 { function foo(mixed $a, mixed ...$args) {} }  // KO

class x4            { function foo($a, $b) {} }
class y4 extends x4 { function foo($b, $c, $d) {} }  // OK!
//class y22 extends x2 { function foo(mixed $a, mixed ...$args) {} }  // KO

class x3            { function foo(mixed ...$args) {} }
//class y3 extends x3 { function foo() {} }  // KO
//class y32 extends x3 { function foo(mixed $a) {} }  // KOx

class x4            { function foo(int $a, int $b) {} }
class y4 extends x4 { function foo(int $b, int $a) {} }  // KO

Method compatibility means that eponymous methods must have the same number of arguments, and compatible types.

One special case is using variadic: with it, it is allowed to remove arguments, as long as they are the same type, and next to the variadic.

With mixed variadic, it is also possible to go from no arguments to one argument. The opposite is not possible: one cannot drop a mixed ...$args once it was added.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026