Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75245 invoked from network); 25 Apr 2008 18:19:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Apr 2008 18:19:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 208.70.128.57 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 208.70.128.57 smtp-gw31.mailanyone.net Received: from [208.70.128.57] ([208.70.128.57:52419] helo=smtp-gw31.mailanyone.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/4F-18287-A9022184 for ; Fri, 25 Apr 2008 14:19:06 -0400 Received: from mailanyone.net by smtp-gw31.mailanyone.net with esmtpsa (TLSv1:RC4-MD5:128) (MailAnyone extSMTP sam@sambarrow.com) id 1JpSVj-0005DR-Q4 for internals@lists.php.net; Fri, 25 Apr 2008 13:19:03 -0500 To: internals@lists.php.net In-Reply-To: <1209137410.6642.9.camel@sbarrow-desktop> References: <1209137410.6642.9.camel@sbarrow-desktop> Content-Type: text/plain Date: Fri, 25 Apr 2008 14:16:02 -0400 Message-ID: <1209147362.20639.7.camel@sbarrow-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Return type hinting patch From: sam@sambarrow.com (Sam Barrow) Can anyone help me with this? Here is the current function declaration rule: T_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING optional_function_return_type { zend_do_begin_function_declaration(&$1, &$4, 0, $3.op_type, NULL, &$5 TSRMLS_CC); } '(' parameter_list ')' '{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); } I want to move "optional_function_return_type" AFTER the parameter list, but I also need to pass it to zend_do_begin_function_declaration. Is this even possible? What I'm trying to acheive is this: function a($arg1, $arg2) return int { } Currently: function a return int($arg1, $arg2) { } On Fri, 2008-04-25 at 11:30 -0400, Sam Barrow wrote: > Attached is my return type hinting patch. It allows type hinting for > parameters and return values. Int, float, bool, string, num, scalar, > resource, object, array, and class names are supported for both > parameters and return values. Objects with __toString methods are > allowed to pass for scalar and string type hints. > > function myTypedFunction returns int(string $stuff, bool, $things, num > $amount) { > return 'This will cause an error.' > } > > I want to move the returns clause after the parameter list, but I > couldn't get it to work in the parser: > > function x($param) returns y { > return new y > } > > Parameters and return values are strict. Int means int (to the type), > etc. For type hinted parameters, null is allowed only if it is the > default value. > > Implementations of abstract functions must be compatible both in their > parameter and return types. Mismatched types will cause an error. > > Note: The parameter type hinting is complete. The return type hinting > works, but there is a small memory leak which I do not know how to fix. > Besides that it's running perfectly, it's very minor obstacle, I'm just > not familiar enough with C to fix this right now. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php