is_numeric is not good enough in some cases, like when searching for value
in MongoDB where it matches agains typed value.

       function age_check(int $age)
       {
           // do stuff
       }

This would require less code, easier to read and will catch wrong type at
runtime easy and throw recoverable fatal error that you can catch. 
the well designed IDE can also catch error in your code if your parameters
and all returnes are typed, so that will also save you a lot of time.




Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytk...@ultralogistics.com
Web: www.ultralogistics.com

"A Top 100 Logistics I.T. Provider in 2011"


-----Original Message-----
From: Stas Malyshev [mailto:smalys...@sugarcrm.com] 
Sent: Thursday, December 22, 2011 1:55 PM
To: Sebastian Bergmann
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC

Hi!

>       function age_check($age)
>       {
>           if (!is_int($age)) {
>               throw new InvalidArgumentException;
>           }
>       }
>
>   With the above code, the caller needs to cast and the writer of the
>   age_check() function has to copy/paste/adapt these checks to all the
>   correct places ...

That's because you should be using is_numeric in this context ;) And 
have an answer on the question "what happens if it's not" that does not 
involve "throwing exception that nobody is going to catch". Of course, 
you can't design proper library in one line. The idea is that strict 
typing doesn't make such design easier, since it does not lead to less work.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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


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

Reply via email to