You need to add a default value like
function foo(Type $t = null) { }
That way you can pass it a null value.
This is described in the section on Type Declarations :
A declaration may be accepted for accepting NULL values โโif the default value for the parameter is set to NULL .
From PHP 7.1 (released December 2, 2016) you can explicitly declare a variable as NULL with this syntax
function foo(?Type $t) { }
this will lead to
$this->foo(new Type()); // ok $this->foo(null); // ok $this->foo(); // error
So, if you need an extra argument, you can follow the Type $t = null convention, whereas if you need to make an argument that accepts both NULL and its type, you can follow the example above.
You can read it here.
DonCallisto Jan 29 '13 at 13:34 2013-01-29 13:34
source share