Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49381 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7218 invoked from network); 11 Aug 2010 20:28:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2010 20:28:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=g.rossolini@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=g.rossolini@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: g.rossolini@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:47522] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/A4-18548-8D7036C4 for ; Wed, 11 Aug 2010 16:28:09 -0400 Received: by vws18 with SMTP id 18so452157vws.29 for ; Wed, 11 Aug 2010 13:28:06 -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=+AV5x/VZWCboHdhfMbms2H6I7GWH5u+/y4Ka5YL4F+c=; b=m5I/5BFsYGePklq6TdpBg7a7Pyj0zd4If7o+d5/tR4JjaI5oG99B0A1BiWZNKxOFmq ASOqyFTdFYd1MQgYsFeu7IjDd0sRgMB6E1D5WXPFVViLbsoexHUvJ899NtpNJ5hOpBsP DWLLMA1+DUq9QxU79Vt7LPyc9zwdTZrBzJ5co= 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=GrLoIbRhBZxrHCfyUfaQl+ehqn+iq2+J23Bu/2zv7tBK8tUDUE7aXDgK/kDRCRX2EZ seYE2xa4UrhfyxoV1YS0qpeK06KIzILINZNZ6/mqayl2RWzq82ubMhMotlKZW8HwSaEX XtIfcAiJsjpIo5wGc60Aw09kw+sHSyDv1l7vo= MIME-Version: 1.0 Received: by 10.220.125.83 with SMTP id x19mr11841942vcr.211.1281558486382; Wed, 11 Aug 2010 13:28:06 -0700 (PDT) Received: by 10.220.186.197 with HTTP; Wed, 11 Aug 2010 13:28:05 -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 22:28:05 +0200 Message-ID: To: Josh Davis Cc: Alexey Zakhlestin , Stas Malyshev , Internals Content-Type: multipart/alternative; boundary=0016369f9dde56faa4048d921687 Subject: Re: [PHP-DEV] Strict typing From: g.rossolini@gmail.com (Guillaume Rossolini) --0016369f9dde56faa4048d921687 Content-Type: text/plain; charset=UTF-8 On Wed, Aug 11, 2010 at 9:29 PM, Josh Davis wrote: > > > 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. > > Hi Thank you for the use case, we need more of them. However in this example, what kind of application wouldn't make this $n parameter configurable (ini file, XML file, user preference from a database etc.) at some point? Then you would be back to square one, meaning you would have to cast your database output so that your strict API accepts the natural evolution of your app. Or you would have to get rid of the strict check and replace it with a userland checking and validation chain (which you should do anyway), at which point you wouldn't need or want type checking but you would be glad to have type casting. In PHP, every single value potentially comes from a kind of stream (file, HTTP or otherwise), there is no such thing as a fully internal configurable value that I can think of. Or is there? If there is, why would it need type checking at all? Type checking or type casting won't save you much trouble since, as you said yourself, in both cases you need to properly validate any data before doing anything funny. However, with type checking you don't get any actual benefit that I can see, while with type casting you can do other things relying on the cast to properly format some of your data for you. If you have a validation chain, why do you need type checking? If you don't validate your data, type checking won't help. It would give a false sense of security, nothing more. In edge cases like you described, type checking leaves you with a broken app (fatal error / white page), while with type casting you'd have a kind of recoverable error that you could... recover from. In neither case your users care what happens internally, so IMO they should not be taken hostage of your design mistakes or your choice of libraries. And yes, if your app fails a typecheck, it means it fails with a fatal error and your users get frustrated. One use case I can think of is during testing, but in this case you can already do the same with a testing framework. Just declare the types in the comments and have the framework use those, but don't let them stand in the way the app actually works. Using strict type checks would be like hard coding your debugging breakpoints, would it not? Best regards, -- Guillaume Rossolini --0016369f9dde56faa4048d921687--