Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36827 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62278 invoked from network); 7 Apr 2008 03:41:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2008 03:41:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=felipensp@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=felipensp@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.166.183 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: felipensp@gmail.com X-Host-Fingerprint: 64.233.166.183 py-out-1112.google.com Received: from [64.233.166.183] ([64.233.166.183:34856] helo=py-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/6A-03324-60899F74 for ; Sun, 06 Apr 2008 23:41:59 -0400 Received: by py-out-1112.google.com with SMTP id u77so1156085pyb.16 for ; Sun, 06 Apr 2008 20:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; bh=2dPjtsgH0AghTV/1w8bd3uGzhz92tH9xbSLdhEkILv8=; b=cgdMNidf4b00gR98sNqi2c5pXGQg5gDKNSg52bMhNwqGwZF9F6rGkwkZ8mqoL9JJbb2JNvQN4gzjybVsSibmfJJcdQJYKwR7/52PJ05WDEdjjEUfShQS+TohAgibrRdqT/QzqYhSefZ9nRxjSZ1yqMEJc7ZLKhhxlknJQcu5bTg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; b=kWF/GBWZPwEub2SDEqW9KNtbM/fggXGTha42keJntfuRahcQ4q5J4v+6VIlM4VElSZ0jzo09TPE5R5dJW4IhoWsMfUTKKlRffiQ1INNrHLT98+Veni0GXabxUgxVDbOup/lfjwjo2lN6GtfnH110xTNqbmV40y/ZwFUVRiBSMlc= Received: by 10.65.193.15 with SMTP id v15mr8132178qbp.55.1207539716165; Sun, 06 Apr 2008 20:41:56 -0700 (PDT) Received: from ?192.168.1.2? ( [189.24.5.190]) by mx.google.com with ESMTPS id e16sm7767963qba.30.2008.04.06.20.41.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 06 Apr 2008 20:41:55 -0700 (PDT) To: internals@lists.php.net Content-Type: text/plain Date: Mon, 07 Apr 2008 00:41:35 -0300 Message-ID: <1207539695.5736.42.camel@pena> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit Subject: Return type hints From: felipensp@gmail.com (Felipe Pena) Hello ladies and gentlemen, I made a patch that implements an experimental return type hint, therefore we need discuss much about this yet, right? :) My idea uses (php-type) and +className as notation, see below. - PHP types function (string) foo(...) { } // Unicode string too function (object) foo(...) { } // Strict function (array) foo(...) { } // Strict function (bool) foo(...) { } // Strict function (int) foo(...) { } // Accepts numeric string function (double) foo(...) { } // Accepts numeric string :: Question --------------------------- - Add (resource), (unicode), (void) ? | --------------------------------------- - Userland types (like actual parameter type-hint) function +className foo(...) { } function +interfaceName foo(...) { } // Uses the class/interface 'int', not the type function +int foo(...) { } :: Question ---------------------------- - Weird syntax? | ---------------------------------------- :: Examples ------------------------------------------------ interface Itest { } class bar implements Itest { } class foo extends bar { } class test { static public function +Itest testing($instance) { return $instance; } } test::testing(new bar); test::testing(new foo); test::testing(new stdclass); // Error! // Catchable fatal error: The returned value must implement interface Itest ----------------------------------------- class foo { public function +self getInstance() { return $this; } } $test = new foo; var_dump($test->getInstance()); // OK! object(foo)#1 (0) { } Finally, it's nice or poor syntax? What must be improved/changed? (All?) Patch: http://felipe.ath.cx/diff/return_type_hint.diff Tests: http://felipe.ath.cx/diff/tests/ -- Regards, Felipe Pena.