On Fri, Apr 18, 2008 at 2:28 PM, Robert Cummings <robert@xxxxxxxxxxxxx> wrote: > > On Fri, 2008-04-18 at 13:54 -0600, Nathan Nobbe wrote: > > On Fri, Apr 18, 2008 at 1:42 PM, Robert Cummings <robert@xxxxxxxxxxxxx> > > wrote: > > > > > Nope, the point is moot. If I've made my properties publicly > accessible, > > > now, due to the ability to trap via __get() or __set(), I can remove > > > them and handle them. Thus, I can retrospectively change the semantics > > > without care for having exposed the properties themselves. The point > is > > > moot here because the option now exists to enhance properties at a > later > > > date without the need to drive the enhancements through a method the > > > user must call (the details of __get() and __set() are hidden from the > > > user of the properties ;) > > > > > > i see your rationale now, and yes i agree, using the magic methods does > > afford the ability to make transparent changes and thats great. > however, > > what im saying is thats still encapsulation, just a different way of > > attaining it. > > I'm not arguing against encapsulation, only indicating that there's no > longer a point to differentiating between method wrapping and property > access in PHP (although maybe there's some fringe differences-- I > haven't played with it much at this time). > > > and the other negative of that approach is having to bulk up > > the logic in the magic methods. i tend to use them to handle attempts > to > > access non-existent params. > > Why bulk up your magic methods? Keep them slim... > > <?php > > class Foo > { > function __get( $name ) > { > if( method_exists( $this, 'get'.ucFirst( $name ) ) ) > { > return $this->{'get'.ucFirst( $name )}(); > } > > return null; > } > > function getName() > { > return 'Namicus Orealeeyus'; > } > } > > $foo = new Foo(); > echo $foo->name."\n"; > > ?> > > Or if you want to pick and choose... > > <?php > > class Foo > { > function __get( $name ) > { > static $map = array > ( > 'name' => 'getName', > ); > > if( isset( $map[$name] ) ) > { > return $this->{$map[$name]}(); > } > > return null; > } > > function getName() > { > return 'Namicus Orealeeyus'; > } > } > > ?> i know; variable functions are cool, but still, i guess it comes down to a matter of prefernce class Foo { function __get( $name ) { if( !is_set( $this->$name) ) { // some logic for handling non-existent getters } return null; } /// only getters i care about function getStuff() {} /// etc .. } ?> -nathan