4 ms·
Union types look somewhat handy, especially if you're using T|null In PHP 7, you can still do function foo(string $bar = null): void Which is a litt
by jonny383 7y ago
Union types look somewhat handy, especially if you're using
T|null
In PHP 7, you can still do
function foo(string $bar = null): void
Which is a little clunky...
- EspadaV9 7y agoIn PHP 7 the correct code should be function foo(?string $bar): void Having `= null` marks the parameter as optional with the default being `null`. Using `?string` means there is no default and you can pass in either a string or null.
- jonny383 7y agoYes thanks. A little rusty on the old PHP knowledge off the top of my head.
- vgaldikas 7y agoYou should have '?' string
- flir 7y agoI'd rather have overloaded function signatures, to be honest. function add(string $a, string$b){} function add(int $a, int $b){}