Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36832 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85714 invoked from network); 7 Apr 2008 05:49:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2008 05:49:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=tim@s3.net.au; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=tim@s3.net.au; sender-id=unknown Received-SPF: error (pb1.pair.com: domain s3.net.au from 207.210.67.178 cause and error) X-PHP-List-Original-Sender: tim@s3.net.au X-Host-Fingerprint: 207.210.67.178 ice.securenet-server.net Received: from [207.210.67.178] ([207.210.67.178:34688] helo=ice.securenet-server.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/72-07930-ED5B9F74 for ; Mon, 07 Apr 2008 01:49:19 -0400 Received: from 123-243-28-123.static.tpgi.com.au ([123.243.28.123] helo=[192.168.23.10]) by ice.securenet-server.net with esmtpa (Exim 4.68) (envelope-from ) id 1JikDo-0003PB-L2; Mon, 07 Apr 2008 01:48:50 -0400 Message-ID: <47F9B5C2.7060308@s3.net.au> Date: Mon, 07 Apr 2008 15:48:50 +1000 User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Felipe Pena CC: internals@lists.php.net References: <1207539695.5736.42.camel@pena> In-Reply-To: <1207539695.5736.42.camel@pena> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ice.securenet-server.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - s3.net.au X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Return type hints From: tim@s3.net.au (Timothy Chandler) I guess I should say it before anyone else does... "It's not the PHP way" - Timothy Chandler Simple Site Solutions Felipe Pena wrote: > 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/ > >