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?
I will prefix this by saying I have come to the conclusion that I do not like the idea of accessors in general, regardless of how they implemented, I have a fundamental problem with the idea of hiding logic behind something that looks like simple property access. It is also difficult to be objective having examined the previous accessor proposal in depth. However, I will be as objective as possible under these circumstances.
1) I don't like it, primarily because it makes the declarations more complicated, not less. The idea of such a feature (for me) would be to make the use of "magic" setters and getters simpler, and this does not seem to deliver on that aspect. However I do agree that it is considerably cleaner than
__get()
and__set()
, which usually result in an unreadable mess.2) Objectively (assuming I actually wanted to treat the values as properties), probably yes. It would not be a big job, I could get EditpadPro to do most of the work with a couple of fairly simple regexes.
3) Not for me personally.
4) No. However the question seems to imply that I don't like the idea of annotations affecting the behaviour of the language, which is not the case. Many people seem to be of the opinion the annotations are akin to comments that affect behaviour, however I do not share this view.