Re: [RFC] Strict type hints (parameter and return value)

From: Date: Thu, 17 Apr 2008 17:11:48 +0000
Subject: Re: [RFC] Strict type hints (parameter and return value)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-37091@lists.php.net to get a copy of this message
On Thu, 2008-04-17 at 10:06 -0700, Chris Stockton wrote: > On Thu, Apr 17, 2008 at 9:57 AM, Stanislav Malyshev <stas@zend.com> wrote: > > > What's the use of such code? If $var is '1' and not 1, what's the use > > of > > throwing an exception and having to handle it later (basically by failing > > the task, since you don't know how to do foo() now) - instead of just doing > > with that 1 what was intended for? There's no any difference between 1 and > > '1' that can be important to anybody. Only difference is the way it is > > represented in underlying bits in zvals, about which nobody should ever > > care. That's like making function that would accept only arguments that has > > 3'rd bit of pointer set to 1 and 5th bit set to 0, and reject all others. No > > sane application should ever behave this way. Writing such function is just > > plain wrong, it replaces the substance of programming with nitpicking over > > the details that are not important. Whole phenomenon of dynamic languages > > has grown on the principle of liberating people from caring for bits and > > concentrate on substance, and now you try to drag the bits back in. > > So every time you call foo you need try/catch? And that's supposed to be > > _good_? > > > Somebody missed the point... > > Seeing how you work for zend I thought maybe you have used the zend > framework = ) Sorry in my example I used "int" instead of "numeric", but my > point is the same, grep in zend framework for is_bool. > > It does what you are complaining about: > > From: Zend_Pdf_Element_Numeric > public function __construct($val) > { > if ( !is_numeric($val) ) { > throw new Zend_Pdf_Exception('Argument must be numeric'); > } > > $this->value = $val; > } > > That could be... > public function __construct(numeric $val) > { > $this->value = $val; > } > > So, let's re-visit my point of "less code bloat".... Actually, is_numeric checks for strings that contain numeric values, it's not the same as is_bool, is_int, is_float, etc, which check the variable's type. Your point is very valid for is_int and similar functions, just not is_numeric(). I just did a grep on zend framework for is_int and there were tons of results.

« previous php.internals (#37091) next »