On Sat, 6 Apr 2019 at 08:53, Guilliam Xavier <guilliam.xav...@gmail.com> wrote: > > Hello internals, > > David and I would like to open the discussion on our joint RFC: > > https://wiki.php.net/rfc/nullable-casting > > Mainly, it would enable to use e.g. `(?int)$x` besides `(int)$x`. >
I'm guessing you don't actually have ths function getIntOrNull() in your code-base? To help me understand where this would be useful, could you provide some 'real-world' code where this would be useful? By the way, this RFC is a special case of something that could be far more generic. If it was possible to register callbacks to be used when casting, people could do something like this: function castToIntOrNull($value) { if ($value === null) { return null; } return (int)$int; } register_cast_function('?int', 'castToIntOrNull'); $x = (?int)getIntOrNull(); > Additionally, it was requested on the mailing list to consider adding > support of nullable types to the settype() function, > e.g. settype($variable, "?int") Someone probably needs to make an argument for it to be in core, rather than just saying that it's something that could be done. cheers Dan Ack -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php