Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Less Arguments In Child Method

<?php

class x {
    function foo(int $a, string $c, string ...$b) {}    
}

// OK
class y extends x {
    function foo(int $a, string ...$b) {}    
}

It is possible to have less arguments in the child method than in the parent one. This is thanks to variadic.

In general, the number of arguments must grow, and, at best, the extra arguments have to be made optional.

That does not apply when there is a variadic argument, and the previous arguments are of the same type. In that case, the child method can have less named arguments than in the parent class. Technically, it goes from ‘one or more’ string argument, down to ‘zero or more’.

All is in the compatibility between the parent and the child class.

Note that it is not possible to apply this if the previous argument is not of the same type as the variadic one. Nor it is possible to add a new argument, even if it looks extracted from the variadic. Both are not compatible with the parent class.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026