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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php