Re: Return type hinting patch
| From: | Michal Dziemianko | Date: | Fri, 25 Apr 2008 21:19:25 +0000 |
| Subject: | Re: Return type hinting patch | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37238@lists.php.net to get a copy of this message | ||
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:
Parser should be able to handle it if the grammar is correct. "something something2 somethign3 int foo(...)" works fine in some languages. LALR parser (Bison is used, isn't it?) is probably the most powerful parser practically used, and certainly can handle such a set of keywords correctly - even without "function" keyword (that makes parsing way easier) - or maybe I have missed some piece of syntax that might cause the problem (then my apologies) As there is a person working on converting parser to Lemon, maybe it would be wise to talk with him (her?), so the grammar is cleaned to handle it.im not sure the following has been explicitly proposed, but how about omitting the 'return' keyword and placing the return type hint before the function identifier function int a($b, $c) {}This is, but I don't think this is possible, due to confusion with the keywords (public, private, static, abstract, etc).
Plus this leads to long strings of keywords.imho it is shorter - one keyword less. Actually it is also less confusing for me - maybe because I am using C/C++ and Java a lot where the syntax is equivalent. And if syntax is strict - i.e. modifiers first, then returned type - is quite well-readable - name of the function in the end, returned type just before. The version with "returns" seems to me like "throws" phrase from e.g. Java. Btw there was already such a solution in Pascal, but instead of "returns" colon was used: function foo(...):integer begin ... end Cheers, Michal Dziemianko PS. The idea is great anyways - I was always thinking why it is not implemented:))