Re: [PHP-DEV] Return type hinting patch

2008-05-01 Thread Keryx Web
Alain Williams skrev: Nice in some ways, except that it is different from the way that type hinting works in PHP5 classes - again: keep to one way of doing things. ': RetType' might be possible, but it is very different from where type hints are given currently in PHP. Stick with:

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Arvids Godjuks
I'm +1 for this syntax function int myfunction(int $param) { return $someint; } C/C++ like, easy to understand And bad idea about making a return type function - looks very useless and will not be used a lot. Work with objects with methods returning an object of some kind, then you can do

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Alain Williams
On Wed, Apr 30, 2008 at 09:23:17AM +0300, Arvids Godjuks wrote: I'm +1 for this syntax function int myfunction(int $param) { return $someint; } C/C++ like, easy to understand +1 -- least confusion to most people. Taking it a bit further, if the function returns a reference (eg to

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Sam Barrow
On Tue, 2008-04-29 at 22:13 -0400, Jessie Hernandez wrote: Sam Barrow wrote: Well in summation I think this is something that should be implemented, I don't see any arguments against implementing this atleast for arrays and classes, like we already have for function parameters. The

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Sam Barrow
On Wed, 2008-04-30 at 09:23 +0300, Arvids Godjuks wrote: I'm +1 for this syntax function int myfunction(int $param) { return $someint; } C/C++ like, easy to understand And bad idea about making a return type function - looks very useless and will not be used a lot. Work with

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Sam Barrow
On Wed, 2008-04-30 at 08:27 +0100, Alain Williams wrote: On Wed, Apr 30, 2008 at 09:23:17AM +0300, Arvids Godjuks wrote: I'm +1 for this syntax function int myfunction(int $param) { return $someint; } C/C++ like, easy to understand +1 -- least confusion to most people.

[PHP-DEV] Re: RE : [PHP-DEV] Return type hinting patch

2008-04-30 Thread Sam Barrow
On Wed, 2008-04-30 at 12:58 +0200, LAUPRETRE François (P) wrote: From: Stanislav Malyshev [mailto:[EMAIL PROTECTED] First is that function definition and code is usually written by the same person in the same (very small) context, and this person has to be somewhat absent-minded

Re: [PHP-DEV] Re: RE : [PHP-DEV] Return type hinting patch

2008-04-30 Thread Chris Stockton
Hello Sam. Would you agree in general the function int name() { syntax is favored? If you need help working out the grammar for such changes let me know. This is something that I think would add value to PHP as a whole and would not mind lending some time for. -Chris On Wed, Apr 30, 2008 at

[PHP-DEV] Re: RE : [PHP-DEV] Return type hinting patch

2008-04-30 Thread Stanislav Malyshev
Hi! Right, return type hinting is useless in such cases, but it is interesting when we check whether a method is compatible with an implemented interface or an extended/abstract class. In this case, When exactly you check that? PHP has no static type checking, and in runtime actual values,

Re: [PHP-DEV] Re: RE : [PHP-DEV] Return type hinting patch

2008-04-30 Thread Chris Stockton
You have added is_int, is_numeric, and === operator. I've been reading your posts and you should really stop confusing using that argument. Truth is, types are relevant. $foo = 1; $bar = '1'; if($foo === $bar) { echo I am never echo'ed; } Until you make $foo === $bar, you should really stop

Re: [PHP-DEV] Re: RE : [PHP-DEV] Return type hinting patch

2008-04-30 Thread Sam Barrow
On Wed, 2008-04-30 at 09:26 -0700, Chris Stockton wrote: Hello Sam. Would you agree in general the function int name() { syntax is favored? If you need help working out the grammar for such changes let me know. This is something that I think would add value to PHP as a whole and would not

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Keryx Web
Alain Williams skrev: Taking it a bit further, if the function returns a reference (eg to its argument): function int myfunction(int $param) Alternative could be: function int myfunction(int $param) But I think that the first form is better. From one whose job it is to

Re: [PHP-DEV] Return type hinting patch

2008-04-30 Thread Alain Williams
On Wed, Apr 30, 2008 at 10:42:04PM +0200, Keryx Web wrote: Alain Williams skrev: Taking it a bit further, if the function returns a reference (eg to its argument): function int myfunction(int $param) Alternative could be: function int myfunction(int $param) But I think that

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Sam Barrow
Well in summation I think this is something that should be implemented, I don't see any arguments against implementing this atleast for arrays and classes, like we already have for function parameters. The only thing left would be to decide on the syntax public array function x() { // Probably

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Pierre Joye
On Tue, Apr 29, 2008 at 5:22 PM, Sam Barrow [EMAIL PROTECTED] wrote: Well in summation I think this is something that should be implemented, I don't see any arguments against implementing this atleast for arrays and classes, like we already have for function parameters. The only thing

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Sam Barrow
Mine uses less code to accomplish the same thing, doesn't introduce new tokens, and has an easier syntax. I'm still working on it, but I can give an update in a couple days. I just wanted to see what people thought about the implementation aspect of it. On Tue, 2008-04-29 at 17:37 +0200, Pierre

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Pierre Joye
On Tue, Apr 29, 2008 at 5:40 PM, Sam Barrow [EMAIL PROTECTED] wrote: Mine uses less code to accomplish the same thing, doesn't introduce new tokens, and has an easier syntax. Ok, sorry to have tried to get this feature in. I do think that going down the way you choosed right now is the best

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread David Zülke
As I've pointed out, public array x() will become ambiguous once we introduce a type function, which is not unlikely at this point David Am 29.04.2008 um 17:22 schrieb Sam Barrow: Well in summation I think this is something that should be implemented, I don't see any arguments

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Stanislav Malyshev
Hi! Well in summation I think this is something that should be implemented, I don't see any arguments against implementing this atleast for arrays and classes, like we already have for function parameters. I think we had plenty of arguments against it last time it was discussed. You could

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Sam Barrow
On Tue, 2008-04-29 at 18:00 +0200, David Zülke wrote: As I've pointed out, public array x() will become ambiguous once we introduce a type function, which is not unlikely at this point That's what I thought, that's why I said number 1 is the most likely. David Am

Re: [PHP-DEV] Return type hinting patch

2008-04-29 Thread Jessie Hernandez
Sam Barrow wrote: Well in summation I think this is something that should be implemented, I don't see any arguments against implementing this atleast for arrays and classes, like we already have for function parameters. The only thing left would be to decide on the syntax public array function

Re: [PHP-DEV] Return type hinting patch

2008-04-27 Thread Alain Williams
On Sat, Apr 26, 2008 at 05:11:29PM -0700, Chris Stockton wrote: *cough* lambda *cough* That would be nice, but the scoping of variables in PHP doesn't seem to make that nice, the code below results in '' Undefined variable: aa '' if I take the 'global' statement out, if I leave it in the echo in

Re: [PHP-DEV] Return type hinting patch

2008-04-27 Thread Rasmus Lerdorf
Alain Williams wrote: On Sat, Apr 26, 2008 at 05:11:29PM -0700, Chris Stockton wrote: *cough* lambda *cough* That would be nice, but the scoping of variables in PHP doesn't seem to make that nice, the code below results in '' Undefined variable: aa '' if I take the 'global' statement out, if

Re: [PHP-DEV] Return type hinting patch

2008-04-27 Thread Larry Garfield
On Sunday 27 April 2008, Alain Williams wrote: On Sat, Apr 26, 2008 at 05:11:29PM -0700, Chris Stockton wrote: *cough* lambda *cough* That would be nice, but the scoping of variables in PHP doesn't seem to make that nice, the code below results in '' Undefined variable: aa '' if I take the

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread Sam Barrow
I like the first too, if this can be implemented I think it is a suitable syntax. On Sat, 2008-04-26 at 00:13 +0100, Alain Williams wrote: public function int doThing(string $foo) { return 1; } The above is the best (ie omit 'return' or 'returns'). This also is consistent with C and with

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread David Zülke
Wouldn't the most consistent way be to omit function altogether when using a return type hint? public static function zomg() { return $somethingArbitrary; } public static string foo() { return $mustBeString; } otoh, should there ever be a type function (e.g. for anonymous funcs) down

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread Nathan Nobbe
On Sat, Apr 26, 2008 at 2:06 PM, David Zülke [EMAIL PROTECTED] wrote: Wouldn't the most consistent way be to omit function altogether when using a return type hint? public static function zomg() { return $somethingArbitrary; } public static string foo() { return $mustBeString; } i

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread David Zülke
Am 27.04.2008 um 00:24 schrieb Nathan Nobbe: On Sat, Apr 26, 2008 at 2:06 PM, David Zülke [EMAIL PROTECTED] wrote: Wouldn't the most consistent way be to omit function altogether when using a return type hint? public static function zomg() { return $somethingArbitrary; } public static

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread Chris Stockton
*cough* lambda *cough* On Sat, Apr 26, 2008 at 4:26 PM, David Zülke [EMAIL PROTECTED] wrote: Am 27.04.2008 um 00:24 schrieb Nathan Nobbe: On Sat, Apr 26, 2008 at 2:06 PM, David Zülke [EMAIL PROTECTED] wrote: Wouldn't the most consistent way be to omit function altogether when using a

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread David Zülke
But anonymous functions and lambda expressions are not the same thing... David Am 27.04.2008 um 02:11 schrieb Chris Stockton: *cough* lambda *cough* On Sat, Apr 26, 2008 at 4:26 PM, David Zülke [EMAIL PROTECTED] wrote: Am 27.04.2008 um 00:24 schrieb Nathan Nobbe: On Sat, Apr 26, 2008

Re: [PHP-DEV] Return type hinting patch

2008-04-26 Thread Chris Stockton
Anonymous functions as you know them today come from lambda calculus which was created before computers were even made. Generally it is agreed anon func == labmda can be used interchangeably. Most developers will understand what: public function lambda sowat () { return function OR lambda,

[PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
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

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Stanislav Malyshev
Hi! In general, it'd be very nice to have some definition of the proposed feature beyond the patch. It would probably answer some of my questions that follow :) parameters and return values. Objects with __toString methods are allowed to pass for scalar and string type hints. What about

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
On Fri, 2008-04-25 at 10:06 -0700, Stanislav Malyshev wrote: Hi! In general, it'd be very nice to have some definition of the proposed feature beyond the patch. It would probably answer some of my questions that follow :) parameters and return values. Objects with __toString methods

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread 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 ')' '{'

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
On Fri, 2008-04-25 at 10:06 -0700, Stanislav Malyshev wrote: I notice it introduces new keyword - returns. Is it necessary? Each new keyword means broken code. I have adapted the patch to reuse the return keyword. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe,

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Alain Williams
On Fri, Apr 25, 2008 at 02:16:02PM -0400, Sam Barrow wrote: 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,

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
Why note the following (which would be more C like): function return int a($arg1, $arg2) { } It gets a little long when you're using classes abstract protected function return int dostuff() { } vs abstract protected function dostuff() return int { } -- PHP Internals

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Stanislav Malyshev
Hi! Why note the following (which would be more C like): function return int a($arg1, $arg2) { } In C I am familiar with return keyword is never used in function definition. -- Stanislav Malyshev, Zend Software Architect [EMAIL PROTECTED] http://www.zend.com/

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
I figured it out, the syntax is now as follows: function a($b, $c) returns d { } I'll post an update soon. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Jeremy Privett
Sam Barrow wrote: I figured it out, the syntax is now as follows: function a($b, $c) returns d { } I'll post an update soon. That's certainly a non-intuitive syntax. How about we take a page out of the book of other C-style languages before trying to invent something else? I agree

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
On Fri, 2008-04-25 at 14:08 -0500, Jeremy Privett wrote: Sam Barrow wrote: I figured it out, the syntax is now as follows: function a($b, $c) returns d { } I'll post an update soon. That's certainly a non-intuitive syntax. How about we take a page out of the book of

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Nathan Nobbe
On Fri, Apr 25, 2008 at 1:15 PM, Sam Barrow [EMAIL PROTECTED] wrote: On Fri, 2008-04-25 at 14:08 -0500, Jeremy Privett wrote: Sam Barrow wrote: I figured it out, the syntax is now as follows: function a($b, $c) returns d { } I'll post an update soon. That's

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
On Fri, 2008-04-25 at 13:24 -0600, Nathan Nobbe wrote: On Fri, Apr 25, 2008 at 1:15 PM, Sam Barrow [EMAIL PROTECTED] wrote: On Fri, 2008-04-25 at 14:08 -0500, Jeremy Privett wrote: Sam Barrow wrote: I figured it out, the syntax is now as follows:

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Chris Stockton
On Fri, Apr 25, 2008 at 12:25 PM, Sam Barrow [EMAIL PROTECTED] wrote: On Fri, 2008-04-25 at 13:24 -0600, Nathan Nobbe wrote: On Fri, Apr 25, 2008 at 1:15 PM, Sam Barrow [EMAIL PROTECTED] wrote: On Fri, 2008-04-25 at 14:08 -0500, Jeremy Privett wrote: Sam Barrow wrote:

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Michal Dziemianko
Hello everybody, I am new here (just reading for last couple of days), so firstly nice to meet you:) This discussion seems quite interesting for me and it would be nice if I can join... Sam Barrow napisal: im not sure the following has been explicitly proposed, but how about omitting the

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Sam Barrow
I don't know, maybe it does work. But either way I'm not introducing a new keyword, I changed the patch to reuse the return keyword. Yes, long strings of keywords: abstract protected string function dostuff() On Fri, 2008-04-25 at 14:22 -0700, Chris Stockton wrote: On Fri, Apr 25, 2008 at

Re: [PHP-DEV] Return type hinting patch

2008-04-25 Thread Chris Stockton
Hello Sam, I think you misunderstand, let me retype for you. strlen('abstract protected function string dostuff()') strlen('abstract protected function dostuff() return string') Making your argument on length void, also, maybe we should not base a language change decision on typing extra