Thank you to everyone who responded, both here and in various other places. I appreciate your feedback. The questionnaire will remain below for posterity's sake.
To clarify a few things:
- I did not intend to mean that we should/can use the
@
symbol for annotations. I should have been more clear to state that this was about the idea of using annotations to dictate what is a setter, not on the exact details here. What symbol is used for annotations is fairly irrelevant if we don't like the idea of using them as a means to declare getters/setters, don't you think? - I'm not sure why everyone likes C# syntax. It seeems that I am a lone man who believes that is a syntactic abomination.
##Greetings, minions of PHP!
I have some questions for all of you. They are regarding annotations in PHP. They also are regarding accessors/properties.
Question #1: What are your initial thoughts on the following (just initial thoughts: not a brain core dump):
class Foo {
private $bar;
@bar.getter
public function getBar() { return $this->bar; }
@bar.setter
public function setBar($value) { $this->bar = $value; }
}
Note that this is not just meta-data; this would behave as follows:
$foo = new Foo();
$foo->bar = 42; // calls $foo->setBar(42);
$bar = $foo->bar; // calls $foo->getBar();
Question #2: Assuming that you had the following code in your codebase, would you go through the effort of transitioning to use accessors/adding the annotations?
class Foo {
private $bar;
public function getBar() { return $this->bar; }
public function setBar($value) { $this->bar = filter($value); }
}
Question #3: Is the value gained by easily transitioning your code to use accessors worth the downsides you listed in response to question #1?
Question #4: Does the fact that Python has a syntax that uses annotations to define accessors change your mind at all?
Question #1:
@
is the error supression operator in PHP. not that I like that operator, but it is an operator. Operators are pretty distinct, so, you can not introduce that operator for a secondary thing like annotations. Even I know it from tags within docblocks, this is not PHP code but comments. However you add@
to PHP code as comments (annotations), however this is PHP code so it's the error supression operator. This means what you outline does not work.Question #2: No because as outlined in Question #1, your suggestion violates the language (I would not consider it a change if I would need to bold'en the argument. I know that's a stretch, but as long as you don't suggest to convert the PHP interpreter to some AST or JIT based on a popular compiler framework I would just say: NO and show you my tongue. Yeah, let's start sexy talk.)
Question #3: Rhetorical. Sure there would have been a value. We probably screwed it too early. So what? Who do we want to blame for the mistake? PHP's legacy? PHP's future? Come on, this is really a rhetorical question.
Question #4: Honestly I've never written a single line of Python code (okay actually I've written one and a half line of python code and did contribute in a popular software that was written in python with a bug-report and even a patch, however, why the hell do you ask? You want to say python is good? Python is bad? I bet, python is a pretty well made scripting language. It's probably not as popular as PHP, however, would you say Wordpress is a good example of a PHP based framework? There you got the answer. NO.