Re: [VOTE][RFC] Safe Casting Functions

From: Date: Mon, 24 Nov 2014 16:11:48 +0000
Subject: Re: [VOTE][RFC] Safe Casting Functions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-79129@lists.php.net to get a copy of this message
> On 24 Nov 2014, at 16:08, Patrick ALLAERT <patrickallaert@php.net> wrote: > > > Le Wed Nov 19 2014 at 10:57:39 PM, Levi Morrison <levim@php.net> a écrit : > - PHP suffers a lot from function bloat and this RFC provides > multiple functions that do the same thing but differ only in how they > handle errors. A simple validation of "can this be safely cast to an > integer without dataloss?" avoid the issue entirely and would be fewer > functions. > > My "no" is mostly for the reason above, mentioned by Levi and also because of the use > of Exception (previously mentioned by Derick as well). > > To improve this RFC, I would: > - use errors/warnings instead of exceptions (unless there is a more global approach on this > aspect for PHP 7). Errors in PHP are horrible to handle. There’s absolutely no question of this RFC being revived using errors, at all. If I must, I’ll wait until exceptions are inevitably approved for core in PHP 7. Assuming they actually are. If they aren’t, I might actually quit PHP... > I would personally appreciate a syntax closer to the current casting mechanism, e.g.: > > $int = (=int) "42"; // result: (int) 42 > $string = (=string) 42; // result: (string) "42" > $int = (=int) "foobar"; // result: E_ERROR: Can not cast (string) > "foobar" strictly to an int > > $int = (~int) "42"; // result: (int) 42 > $int = (~int) "foobar"; // result: E_WARNING: Can not cast (string) > "foobar" strictly to an int PHP already already has enough bizarre syntaxes, I don’t think it needs even more. -- Andrea Faulds http://ajf.me/

« previous php.internals (#79129) next »