Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37091 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23520 invoked from network); 17 Apr 2008 17:14:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2008 17:14:15 -0000 Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 208.70.128.105 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 208.70.128.105 smtp-gw79.mailanyone.net Received: from [208.70.128.105] ([208.70.128.105:44185] helo=smtp-gw79.mailanyone.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/69-05127-66587084 for ; Thu, 17 Apr 2008 13:14:14 -0400 Received: from mailanyone.net by smtp-gw79.mailanyone.net with esmtpsa (TLSv1:RC4-MD5:128) (MailAnyone extSMTP sam@sambarrow.com) id 1JmXgZ-0003qV-Hb; Thu, 17 Apr 2008 12:14:11 -0500 To: Chris Stockton Cc: Stanislav Malyshev , Felipe Pena , internals@lists.php.net In-Reply-To: References: <46ccd1ab0804170742g142ed562t4f03339da549a820@mail.gmail.com> <48077BD2.2000107@zend.com> <48078168.1070801@zend.com> Content-Type: text/plain Date: Thu, 17 Apr 2008 13:11:48 -0400 Message-ID: <1208452308.6148.3.camel@sbarrow-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Strict type hints (parameter and return value) From: sam@sambarrow.com (Sam Barrow) On Thu, 2008-04-17 at 10:06 -0700, Chris Stockton wrote: > On Thu, Apr 17, 2008 at 9:57 AM, Stanislav Malyshev 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.