Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34373 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88794 invoked by uid 1010); 3 Jan 2008 23:54:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 88779 invoked from network); 3 Jan 2008 23:54:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2008 23:54:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=pstradomski@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pstradomski@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.186 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pstradomski@gmail.com X-Host-Fingerprint: 209.85.128.186 fk-out-0910.google.com Received: from [209.85.128.186] ([209.85.128.186:9843] helo=fk-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5E/E5-20810-9A57D774 for ; Thu, 03 Jan 2008 18:54:17 -0500 Received: by fk-out-0910.google.com with SMTP id f33so7311977fkf.7 for ; Thu, 03 Jan 2008 15:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; bh=qB6/JyFihvE/KIAZgmT77p982cZIF5lKURJzcmnhcpU=; b=wocKjBv/VUuA6tKsDw0gmux8y7w6/I4klj/cSFO1OesBJMAbQoefHfxehcK5qlPTX1cELjDKc9wEam8ivgzQ9jGDWR3vUPRTKFvnSYcvz07HplrauvGtS4PD9b5lqmjf+F05H4kRVgAjC2dHIUgMWyNN2qOcDKiYDywjwMCCEDk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=emFagN20bZ9rjGt0nCmxlAtErOcxAtUZAAesjXgDeTz+1tCmk6JvrnQUiRaCSix2Ii9d8S5UEhmEHoobFoBm8/C0vWCsy0pJy0z50P9aBMMZxiR92bzIusbq6lToJqIM1SVMtTCmngTyyfr6Hs6fQW8zVktxQsHBCTgy1/V/7zY= Received: by 10.82.145.7 with SMTP id s7mr28720251bud.7.1199404454426; Thu, 03 Jan 2008 15:54:14 -0800 (PST) Received: from charon ( [91.196.215.2]) by mx.google.com with ESMTPS id 33sm24086305nfu.9.2008.01.03.15.54.12 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Jan 2008 15:54:13 -0800 (PST) Reply-To: =?utf-8?q?Pawe=C5=82_Stradomski?= To: internals@lists.php.net Date: Fri, 4 Jan 2008 00:55:10 +0100 User-Agent: KMail/1.9.7 Cc: Stanislav Malyshev References: <200801031903.01980.tomi@cumulo.fi> <200801040008.43944.pstradomski@gmail.com> <477D6E68.5090501@zend.com> In-Reply-To: <477D6E68.5090501@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-ID: <200801040055.10360.pstradomski@gmail.com> Subject: Re: [PHP-DEV] RE: Optional scalar type hinting From: pstradomski@gmail.com (=?utf-8?q?Pawe=C5=82_Stradomski?=) W li=C5=9Bcie Stanislav Malyshev z dnia pi=C4=85tek 04 stycznia 2008: > > This code is just a good argument *FOR* type hints. When foo is: > > function foo(int $bar) {...} > > and you want the code to die if $bar is not integer, then foo($bar) wou= ld > > be > > Why would you want it? I wouldn't want my code to die, I would want it > to work. You wrote: > With strict checking, that means instead of calling: > foo($bar); > you'd have now to do: > if(is_integer($bar)) { > =C2=A0 =C2=A0 // stupid foo() call would blow up if passed not integer, s= o I have > to manually handle it > =C2=A0 =C2=A0 // oh wait, actually I don't have any way to handle it - I = need > foo() to be called to proceed > =C2=A0 =C2=A0 // so let's just > =C2=A0 =C2=A0 die("can't call foo() because \$bar is not integer"); > } This shows that you explicitly die() if $bar is not integer. But with stric= t=20 type hinting this is unneccessary - the script would automatically die if=20 $bar was not integer. In other words, with strict scalar type hinting the=20 above would behave just like=20 foo($bar) with the only difference being the error message (in your version you've go= t=20 your own error message, automatic script failure would raise some built-in= =20 error - which IMO should be E_RECOVERABLE_ERROR, as E_FATAL gives blano=20 output on production sites where display_error is 0). Not that I care if scalar type hinting is implemented or not, I just wanted= to=20 point out that your example is just plain wrong. > > > you have either an int or string representing an integer in $bar, then > > foo((integer)$bar) would work just well. > > And then how exactly strict typing helps you? Here it doesn't help, but is easy to work around if you are sure you know w= hat=20 you're doing. This is the same workaround that is needed if someone used=20 if (! is_integer($bar)) {die()} inside of the foo method. =2D-=20 Pawe=C5=82 Stradomski