Re: [PHP7] Remove the function keyword from class methods?

From: Date: Sat, 04 Oct 2014 20:14:21 +0000
Subject: Re: [PHP7] Remove the function keyword from class methods?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-77782@lists.php.net to get a copy of this message
On 03/10/2014 18:57, Ingwie Phoenix wrote:
C++ does not use a function keyword by itself, and even lesser visibility keywords as PHP does.
There have been a couple of comparisons to other languages brought up, but I find them unconvincing. Most languages have some keyword for introducing methods: "def" in Ruby; "sub" in Perl (or "method" when using some of the OO helper extensions such as MooseX::Declare); "defun" in Common Lisp; "procedure" (or "function") in Pascal; etc In C-based languages including C++ and Java, the return type of a function is a compulsory part of the function definition, so a definition never begins simply "foo() { ... }". This gives the code structure a very different feel to loosely typed languages. ECMAScript 6 is an interesting exception which someone mentioned. But then, ECMAScript 6 is quite a strange language, really - it grafts a "class" concept onto a prototype-based type system, and includes a whole set of different sub-routine declarations to overcome limitations in earlier versions of the language, as summarised here: http://www.2ality.com/2013/08/es6-callables.html Now, obviously, PHP doesn't have to follow like a sheep wherever other languages go, but if I read a line in the change log for PHP 7 of "function keyword is now optional for methods", my reaction would be a bemused "why?", followed by a mental note to require it in any coding standards I have influence over. -- Rowan Collins [IMSoP]

« previous php.internals (#77782) next »