Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91953 invoked by uid 1010); 29 Jul 2007 15:42:37 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 91938 invoked from network); 29 Jul 2007 15:42:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2007 15:42:37 -0000 Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.166.179 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 64.233.166.179 py-out-1112.google.com Received: from [64.233.166.179] ([64.233.166.179:23029] helo=py-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/22-03166-C65BCA64 for ; Sun, 29 Jul 2007 11:42:36 -0400 Received: by py-out-1112.google.com with SMTP id f31so4182287pyh for ; Sun, 29 Jul 2007 08:42:34 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:cc:references:in-reply-to:subject:date:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language:message-id; b=P+v/NghpzAvbkqawtskHd/DH2d3ce4+/2mI/l+cDt9c02XkmpNt8m9gSsfRgeP2rFnEV/56yVOx+LPIzYMfOBTetOH84wXQozGVzGK7Z7EA0v3gQZUtstn5952hr4VCTSy0LpwOdzqAzg0s3MMovV4tIv3sQ7+1s1rDV0Ul4gRs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:to:cc:references:in-reply-to:subject:date:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language:message-id; b=RyFn1hypjfIgf0eDIHoiQ0KsFZfrPywZeiAWY8YGc1B3dqL4VbizTbeDZcmw8au7DG/SvdYNCzKRiSYg8q4zvNruJGXcAddxEEcjrup3yn9Rg+VXzsLlniJu5IdqIaSpY69c1UihyrptWaGPlB8n+F+3jTEe40NqmBFP/bc9Ato= Received: by 10.35.12.10 with SMTP id p10mr16653431pyi.1185723753952; Sun, 29 Jul 2007 08:42:33 -0700 (PDT) Received: from WillPC ( [12.207.104.174]) by mx.google.com with ESMTPS id u6sm1668260pyb.2007.07.29.08.42.32 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 29 Jul 2007 08:42:33 -0700 (PDT) To: "'Stanislav Malyshev'" Cc: "'Jeremy Privett'" , "'Larry Garfield'" , References: <74.B1.05050.EADEC964@pb1.pair.com> <08.07.20814.2587AA64@pb1.pair.com> <46ABD596.3060005@zend.com> <200707281905.27822.larry@garfieldtech.com> <46abe6c8.4f99220a.6e0c.2bb5@mx.google.com> <46AC4A9B.9070704@zend.com> In-Reply-To: <46AC4A9B.9070704@zend.com> Date: Sun, 29 Jul 2007 10:42:25 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcfRt3B/rXl3iMAjQYmd0oPPPXfSbwAPN1lg Content-Language: en-us Message-ID: <46acb569.0661220a.3591.ffffb051@mx.google.com> Subject: RE: [PHP-DEV] Re: Type-hinted return values in PHP5? From: will.fitch@gmail.com ("Will Fitch") I see your point, but maybe I didn't explain myself well enough. Take the example of an interface. Interfaces aren't directly accessible (callable), they don't have any functional code in them. So why have them? What is the single best advantage of an interface, especially in a very large organization? It ensures consistency. Take PDO for instance. They are a perfect candidate for interfaces. The actual implementation of the close() method will differ based on the RDBMS, but functionally, to the end-developer, they are the same. It closes the database connection. Once a class implements an interface, and the end-developer knows this, they don't have to worry about the name of the method that closes the connection. Also, if the lead architect decides that there must be a method called foo() in each of the given libs, he/she needs only to enforce this through the interface, which is implemented by each class! This can also assist in debugging. I understand that there's a real difference between type-hinting return values and parameters, but reverting back to the interface practice, why not depend on the developer to add a new form of documentation to "promise" to implement certain methods? Will -----Original Message----- From: Stanislav Malyshev [mailto:stas@zend.com] Sent: Sunday, July 29, 2007 3:07 AM To: Will Fitch Cc: 'Jeremy Privett'; 'Larry Garfield'; internals@lists.php.net Subject: Re: [PHP-DEV] Re: Type-hinted return values in PHP5? > On one hand I agree, since PHP is so loosely typed. But it's hard to make > the argument that type-hinting return values is pointless, since PHP allows > (class) type-hinting with parameter values. I personally think type-hinting > is very nice, and not for the purposes of IDEs. The difference is that typehinting works this way: 1. I'm a library, I want to get type X for $foo 2. I put typehint, so I didn't need to check if $foo is X 3. If you pass not X to $foo, my code is going to tell you that you can't do that And return type works like that: 1. I'm a library writer that says foo() returns X 2. I have to use for it, since I don't use foo() 3. You're client, so you read the docs and see foo() returns X 4. You write code which supposes foo() always returns X 5. I decide these return types are more trouble than they are worth, and make foo() return false on error, removing return type. 6. Your code has no way to check I did that, so it's broken now. Basically, it sums up to documentation - if documentation isn't right (or if it changed and you didn't follow) your code is going to break and you have no way to prevent it. That's what you have now with @return - why add language construct? > If one of the best selling points of PHP is its typeless environment, then > why make any of these available? It appears that we are moving more and If it was up to me, I'd probably not bother adding input typehints either :) But as I said above, input typehints are significantly different from return types. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com