Re: Dropping requirement for `function` keyword for methods in classes/interfaces/etc

From: Date: Tue, 19 Feb 2013 21:42:46 +0000
Subject: Re: Dropping requirement for `function` keyword for methods in classes/interfaces/etc
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-65996@lists.php.net to get a copy of this message
Seems this would complicate the transplanting of (global) functions into (default public) class methods and vice versa. This is a common refactoring task -- at least IME -- and before I adjust visibility I would expect the function to Just Work. So this works in a class to define the function: function my_function() { } And I expect to be able to pull that out into the global scope as-is. But if people start using this super-shorthand in the class: my_function() { } Then when I pull it out into my function library, I'll get errors. The reverse is also true: I expect to get a fatal from leaving off a semicolon between function_call() and {} but at the top level of a class it gets smoothly compiled as a function definition. Look, I know there are similar cases throughout PHP (and other languages) already, but why add more for no (IMO) payoff? Perhaps not the most compelling case against this new sugar, but it would suffice to stop me from ever using it. -- Sandy

« previous php.internals (#65996) next »