Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC)
| From: | Lester Caine | Date: | Sun, 22 Feb 2015 22:22:48 +0000 |
| Subject: | Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83495@lists.php.net to get a copy of this message | ||
On 22/02/15 18:37, Zeev Suraski wrote:
> Variant* calc(Variant& val1, Variant& val2) {
> if(val1.isInt() ) {
> // type checking
> if (!val1.coerceToInt()) {
> throw new RuntimeError()
> }
> If (!val2.coerceToInt()) {
> throw new RuntimeError();
> }
>
> // function body begins here
> int result = Variant(val1.intValue() + val2.intValue());
> return result;
> }
A more practical example would be to replace coerceToInt() with
inRange() which includes an int check/'coerce' as part of the range
check, and produce a number of errors based on the result.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk