Keep Interface New Argument Compatible

By Jerome Tamarelle

<?php

class X
{
    /**
     * @param int $nbToken
     *
     * @pslam-param int<1, max> $nbToken
     */
     public function mark(string $place, /*, int, $nbToken = 1 */): void
     {
         $nbToken = 1 <  unc_num_args() ? func_get_arg(1) : 1;
     }

}

A reminder for maintainers of PHP libraries: adding a parameter to a method of an interface causes a fatal error in all the classes that implement it. It’s a BC break that should be prohibited in a minor version.

In Symfony, we add the parameter virtually using phpdoc, and read it using func_get_arg().

See Also

PHP Features

Last updated: 14 July 2026