Hi 2011/12/6 Rasmus Schultz <ras...@mindplay.dk>
> On Tue, Dec 6, 2011 at 3:45 AM, Christian Kaps <christian.k...@mohiva.com > >wrote: > > > Hi, > > > > I also find this syntax confusing and I think it has a huge WTF factor. > > > > Some thoughts about the syntax: > > - At the first glance, it isn't clear which visibility the getter or > > setter has > > - The extra indentation level makes the code more unreadable > > > > class Foo { > > > > /** > > * > > */ > > private $_bar; > > > > /** > > * > > */ > > public $bar{ > > > > /** > > * > > */ > > set { > > if ($bar) { > > $this->_bar = $bar * 12; > > } else { > > $this->_bar = 0 > > } > > } > > > > /** > > * > > */ > > private set { > > if ($this->_bar === null) { > > return 0; > > } > > > > return $this->_bar; > > } > > } > > > > /** > > * > > */ > > public function baz() { > > > > } > > } > > > > - What about type hints? > > > > I prefer a more AS3 like getter and setter syntax. > > http://help.adobe.com/en_US/**ActionScript/3.0_**ProgrammingAS3/** > > WS5b3ccc516d4fbf351e63e3d118a9**b90204-7f30.html#** > > WS5b3ccc516d4fbf351e63e3d118a9**b90204-7fcb< > http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f30.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7fcb > > > > > > Have you read my previous mail http://news.php.net/php.**internals/56762 > <http://news.php.net/php.internals/56762> > > . > > I think this syntax fits more to PHP because its similar to the already > > existing(magic) getter and setter syntax. > > > > What do you think? > > > > Christian > > > > I agree with all of those points - the extra indentation looks messy, and > yes, type hints are important. It does fit better with PHP in general. > > It would be nice to also have support for automatic backing fields in > addition though - so something simple like this: > > class BlogPost > { > private $_author; > > public get author() > { > return $this->_author; > } > > public set author(Person $value) > { > $this->_author = $value; > } > } > > Could be written like this: > > class BlogPost > { > public Person $author; > } > > Effectively, this shorthand syntax just gives you type-safe properties - > but it refactors nicely, since you can replace it with a full > implementation of a backing field at any point. > > (on second thought, I don't like the idea I suggested before - adding a > magical $value in accessors, similar to $this - it's confusing and it's > going to look like an undeclared local variable...) > Because it seems everybody throws in their preferred syntax :X class X { public $myProperty { /* public *inherited* */ set (AnotherClass $value) { // Value from "outside" return $value; // Set to property } private get (AnotherClass $value) { // Value from property (Maybe with typehint) return $value; // returns value to the caller } } /* = 'default value'; */; } * No _magic_ $value * Type-Hints * I think nearly no suprise, what happens here In my eyes the goal should be to _not_ separate a property from its accessor anymore, which disqualifies both of Rasmus Schultz suggestions. At least this is _the_ reason, why I want to see this RFC to be implemented.