Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63247 invoked from network); 2 Jul 2009 07:28:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2009 07:28:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.117 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.117 us-mr1.zend.com Linux 2.4/2.6 Received: from [63.205.162.117] ([63.205.162.117:34239] helo=us-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/A1-54262-6A16C4A4 for ; Thu, 02 Jul 2009 03:28:39 -0400 Received: from us-gw1.zend.com (us-ex1.zend.net [192.168.16.5]) by us-mr1.zend.com (Postfix) with ESMTP id 36DE1E12BB for ; Thu, 2 Jul 2009 00:17:32 -0700 (PDT) Received: from [192.168.27.29] ([192.168.27.29]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 2 Jul 2009 00:29:11 -0700 Message-ID: <4A4C61A1.1090602@zend.com> Date: Thu, 02 Jul 2009 00:28:33 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Ilia Alshanetsky CC: PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 02 Jul 2009 07:29:11.0827 (UTC) FILETIME=[CB602E30:01C9FAE6] Subject: Re: Flexible type hinting From: stas@zend.com (Stanislav Malyshev) Hi! > 2) Type hinting will not create a mess of cast to the right types in the > code as Stas had suggested, in close to a million lines of PHP code we > have, I've been able to find less then 1000 (just did a grep) instances > of casts. There is a good reason for that once you get out of the input > processing stage you typically (aside from __toString()) have the data > in the right type. The code also includes bits from PEAR and external The problem here is that if you want to write a robust code that wouldn't randomly fail at runtime "typically" isn't good enough - since wrong type is supposed to be a fatal error (which one could not handle in the typehinted library code since it happens on the client side before your code takes control), you would want to ensure that would never happen when you call a typedhinted function. And there's only two ways to do it - either make absolutely all functions and variables that interact with typehinted functions to be strict-typed (which we don't plan do) or do casts on each call to hinted function. I do not see how anything else could produce robust code provided that type mismatch is a fatal error and variables can not carry type. > "stock php" for people to use. But please, don't reject this idea > because you personally don't see yourself using it or because you want Being a C programmer for... hmm... about 20 years now I think I don't have too much problem with strictly typed languages :) I just think doing it in PHP the way you want to do it is going to produce a lot of issues that people tend to under-appreciate when they cheer the new cool feature. Also, looking at the patch I think it doesn't cover the matter of inheriting the typehinted methods - i.e. if there's a typehinted method, could I override it with non-typehinted version or vice versa? What about typehinted interfaces? -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com