Re: [RFC] Nullable Casting

From: Date: Mon, 08 Apr 2019 02:54:44 +0000
Subject: Re: [RFC] Nullable Casting
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-105136@lists.php.net to get a copy of this message
On Sat, 6 Apr 2019 at 08:53, Guilliam Xavier <guilliam.xavier@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

« previous php.internals (#105136) next »