Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37106 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52940 invoked from network); 17 Apr 2008 18:10:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2008 18:10:33 -0000 Authentication-Results: pb1.pair.com header.from=jarismar_silva@adplabs.com.br; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jarismar_silva@adplabs.com.br; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adplabs.com.br designates 201.84.224.130 as permitted sender) X-PHP-List-Original-Sender: jarismar_silva@adplabs.com.br X-Host-Fingerprint: 201.84.224.130 mail.adplabs.com.br Linux 2.5 (sometimes 2.4) (4) Received: from [201.84.224.130] ([201.84.224.130:53716] helo=kafe.adplabs.com.br) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/AF-05127-59297084 for ; Thu, 17 Apr 2008 14:10:32 -0400 Received: from [10.159.1.169] (jarismar.adplabs.com.br [10.159.1.169]) by kafe.adplabs.com.br (Postfix) with ESMTP id AAB4F1F90B5; Thu, 17 Apr 2008 15:10:23 -0300 (BRT) Message-ID: <480792A4.2080306@adplabs.com.br> Date: Thu, 17 Apr 2008 15:10:44 -0300 User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Stanislav Malyshev CC: Chris Stockton , Felipe Pena , internals@lists.php.net References: <46ccd1ab0804170742g142ed562t4f03339da549a820@mail.gmail.com> <48077BD2.2000107@zend.com> <48078168.1070801@zend.com> In-Reply-To: <48078168.1070801@zend.com> Content-Type: multipart/alternative; boundary="------------050409090001030600040400" X-ADPLabs-MailScanner-Information: Please contact your ISP for more information X-ADPLabs-MailScanner: Found to be clean X-ADPLabs-MailScanner-From: jarismar_silva@adplabs.com.br X-Spam-Status: No Subject: Re: [PHP-DEV] [RFC] Strict type hints (parameter and return value) From: jarismar_silva@adplabs.com.br (Jarismar Chaves da Silva) --------------050409090001030600040400 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I like and will use it a lot... sometimes you simple cannot trust on php dynamic type convertion, please see the following example 0 && $user_id < 1000) { // special admin users } else { // standard users } } ?> Now if someone thinks $user_id is the user login name and call check_user(''); '' will be converted to 0 (zero) as per php automatic string to numeric convertion and this user will be handled as being the root user. In this case strict comparison "===" is not apropriate, and I'm forced to verify the parameter against is_numeric. I much simpler approach would be... Hi! > >> So: >> function foo($var) { if(!is_int($var)) { throw new exception('not >> int'); }} > > 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. > >> which is called like this in both cases, maybe with a try catch etc etc: >> foo((int) $baz['bar']); > > So every time you call foo you need try/catch? And that's supposed to > be _good_? -- *Jarismar Chaves da Silva, M.Sc.* --------------050409090001030600040400--