Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49369 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88535 invoked from network); 11 Aug 2010 19:29:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2010 19:29:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=phpwnd@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=phpwnd@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: phpwnd@gmail.com X-Host-Fingerprint: 209.85.210.42 mail-pz0-f42.google.com Received: from [209.85.210.42] ([209.85.210.42:38428] helo=mail-pz0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/E0-18548-D2AF26C4 for ; Wed, 11 Aug 2010 15:29:50 -0400 Received: by pzk30 with SMTP id 30so212427pzk.29 for ; Wed, 11 Aug 2010 12:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=zYRsoUY+j7ZYfJlVSa/jwiSarTW23XSngSipfakrCso=; b=TidhrFKn+i1IalF1K+YKntvZ1Gv+PXDVOA149efqX+P0DH82j0Wq2DC3kG2TuTuaxT t+TRKGIXWyqde7aVguQ3hadrQ/a05t9OS6z8O+Mpex5bcq+Z9ElFJMoNLcift+Irt2px ZpRXT5nDSD8SWHHCKjlggms4Erf9rnLzqGa68= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=jCi4RIpulcu+z95li4w0ilxGIODphaS/FQbZe631nrRMFyXbQt9aUZwo/0VZrh4Nx9 NLiDJ8aEPB07VX8ZKS5rxOP49OAlDX0JlGUIeDkofzD8tP++rDdY2Jg1LoHRSWIixEHN uCPwJ15dHiBgar7vlSFw4nflo19TFL0X53J9g= MIME-Version: 1.0 Received: by 10.114.95.12 with SMTP id s12mr22446156wab.226.1281554986472; Wed, 11 Aug 2010 12:29:46 -0700 (PDT) Received: by 10.114.154.9 with HTTP; Wed, 11 Aug 2010 12:29:46 -0700 (PDT) In-Reply-To: References: <1281478269.6608.292.camel@guybrush> <4C61E5CA.5070604@sugarcrm.com> <4C61F3EF.5030409@sugarcrm.com> <4C6241D1.6030909@sugarcrm.com> Date: Wed, 11 Aug 2010 21:29:46 +0200 Message-ID: To: Alexey Zakhlestin Cc: Stas Malyshev , Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Strict typing From: phpwnd@gmail.com (Josh Davis) On 11 August 2010 19:11, Alexey Zakhlestin wrote: > Did you read second RFC? The one which is about "so called" weak typehinting. > Stas (and a lot of people on this list) prefer it. > http://wiki.php.net/rfc/typecheckingstrictandweak Yes of course, but reposting that link is a good idea. :) > If you did, can you tell if there is some case, when it doesn't work for you? If I'm using type checking as a sanity check then it doesn't work as soon as it accepts "1" for an int. The described "weak typehinting" is good if you're looking for a way to validate input. However, it does not work if you're trying to make sure that Stuff Is Going As Planned(tm). For example, consider a protected method getTheNextNTokens(int $n) which is part of some tokenizer or something. It is a protected method and you never write getTheNextNTokens("2") so if it ever receives something that is not an integer, it means that there's a subtle bug somewhere. In that case, "strict typehinting" buys you peace of mind. If your function lives in a controlled environment (e.g. private methods, or because your specifications require to use the filter extension to validate input) then checking for the type of a variable offers more protection against the unexpected than checking for its contents. Of course, it's not an absolute protection, just like making a method private does not guarantee that a user [of your code] won't extend it to make it public or use ReflectionMethod to make it accessible. It's just another way to defend against the unexpected. I hope it answers your question :)