Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40880 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96301 invoked from network); 7 Oct 2008 20:05:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Oct 2008 20:05:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=shawnmc@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=shawnmc@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.46.31 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: shawnmc@gmail.com X-Host-Fingerprint: 74.125.46.31 yw-out-2324.google.com Received: from [74.125.46.31] ([74.125.46.31:17920] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/9F-48736-401CBE84 for ; Tue, 07 Oct 2008 16:05:24 -0400 Received: by yw-out-2324.google.com with SMTP id 5so669177ywb.83 for ; Tue, 07 Oct 2008 13:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=AOT+TOufyZZoPlSkJ4Dmm0PSAmUJ7KtSXzgaTFmBEfM=; b=DVsfAD4uU259aFxi56kTD/kaHhLcfujq+tFSkaIsVfsTnWsbtlfOvDVxM83z+a+sBz e+1TPhoSlMv5kgA8tLdKf5BAgs3bP18uszHvLe3R8IIakimxhr0DdaMmEdcwqj6jEZvR GZBMA/CMMl9cEuSleuLuZZSl1UU2n4cMQ1Gg8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=sArEKAHdhCfa7KNy+ogWaRX6dZZURZY2Ip6DI9xEsdhs4570j4XBCxbPnRuK9W0Dj/ 5vkQxDH7RVHBHP5+DRun+24MZJTtSae/y/SK3e/Hcnn8oaXg4CAk3v8OIWzUWZULRRnA g8aOdXX8b5i9yF3AHmYKO42SkMRa35ySAngIQ= Received: by 10.142.48.14 with SMTP id v14mr2937758wfv.133.1223409920538; Tue, 07 Oct 2008 13:05:20 -0700 (PDT) Received: by 10.142.163.19 with HTTP; Tue, 7 Oct 2008 13:05:20 -0700 (PDT) Message-ID: Date: Tue, 7 Oct 2008 15:05:20 -0500 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_55562_7483551.1223409920564" Subject: Type hinting return values From: shawnmc@gmail.com ("Shawn McCool") ------=_Part_55562_7483551.1223409920564 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, I've submitted this suggestion once before, but it was quickly shunned with two generic answers: "It's not the PHP way" and "It all boils down to documentation. That's what PHPDoc is for." Both of those are partially correct, but I feel the benefits and other uses certainly make a better case. While type hinting return values from class methods is not the current PHP way, neither were abstracts, interfaces, namespaces or even object-orientation if you go back far enough. PHP is constantly evolving, and that evolution derives from other languages, programming techniques and innovation (which PHP certainly contributes to). Obviously this scenario is standard in other languages and are typically absent from the scripting type. Adding type hinting for parameters was huge and this functionality will compliment it. For those who are worried about generic (mixed) return values and backwards compatibility, we could allow the keyword "function" to remain in place and represent a generic return type. While there are concerns of performance with this additional hit on the Zend Engine, I still feel it's worth exploring. Although documentation is inherently created, it is not the purpose of type hinting return values. Devs working in multi-developer environments, library authors and others directly benefit from this. There are no surprises when the return value of a method call is declared a reference of "SomeClass". If the class author attempts to return "OtherClass", the error, E_ERROR in this case, would be thrown in the method that declared that return type, making debugging and ultimately responsibility easier to identify. What value does prefixing a class method with the keyword "function" provide? I understand that PHP's evolution is the result of this, but if we allowed the substitution with a class name, scalar or compound type, no harm would be done. I feel it's reasonable to reopen the conversation of this subject for the purpose of justifying adding the functionality or doing nothing at all. We seen the need for parameter type hinting, which eliminates the need for logical checks, and implemented it. What disadvantages are there for doing the same with method return values? ------=_Part_55562_7483551.1223409920564--