Hi Andrea,

> On 21 Oct 2014, at 00:57, Andrea Faulds <a...@ajf.me> wrote:
> 
> Good evening,
> 
> I am presenting a new RFC to add a set of three functions to do validated 
> casts for scalar types:
> 
> https://wiki.php.net/rfc/safe_cast
> 
> Please read it.


I like the proposal except for one thing: the functions returning false in case 
of an error. As the next logical function would be "to_bool()", I foresee a lot 
of trouble with regards to API design as returning false there either means 
successful cast to false or an error while casting. What about changing the 
functions to take an $isError variable as a second argument?

$value = to_string(1.2, $isError);
if ($isError) {
   ...
}

Alternatively one could do the same thing with an $isSuccess variable:

$value = to_string(1.2, $isSuccess);
if (!$isSuccess) {
   ...
}

Thoughts?

cu,
Lars



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to