On 23/04/2019 14:39, Mark Randall wrote:
It keeps coming back to the feature we've all been praying to the PHP
Gods for... generics.
Replying to myself (sorry).
I just wanted to point out that the same syntax would also solve your
other issue from the nullable casts thread:
function ncast<type T>($value) ?T {
if ($value === null) {
return null;
}
if (settype($value, T) === false) {
throw new InvalidArgumentException('Cannot convert to ' . T);
}
return $value;
}
ncast<int>(null);
ncast<int>(12345);
ncast<string>(null);
ncast<string>('abcdef');
--
Mark Randall
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php