Re: [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Tue, 15 Jul 2014 17:52:52 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-75556@lists.php.net to get a copy of this message
On 15 Jul 2014, at 18:39, Rowan Collins <rowan.collins@gmail.com> wrote: > Ooh, skimming that, I see suggestions for prefixes and suffixes to represent types of cast (or > hint). > > That fits nicely with my thoughts on making "strict cast" a first-class citizen of > the language, rather than isolating it to function signatures, e.g.: > > $foo = 'abc'; $foo = (int)$foo; // OK, evaluates to int(0) > $foo = 'abc'; $foo = (int!)$foo; // ERROR > $foo = '42'; $foo = (int!)$foo; // OK, evaluates to int(42) It’s a shame Nikita’s Exceptions in the Engine RFC failed, as being able to do this would be nice: try { $foo = (int!)$foo; } catch (RecoverableError) { $foo = 1; } Perhaps some sort of similar syntax? (int!)$foo else 0? -- Andrea Faulds http://ajf.me/

« previous php.internals (#75556) next »