NYCPHP Meetup

NYPHP.org

[nycphp-talk] Getter/setter best practices

Yitzchak Schaffer yitzchak.schaffer at gmx.com
Tue Jan 12 11:58:55 EST 2010


Hello all,

What's BP for changing the values of protected properties within a class 
that also has public getter/setters?  e.g. in Foo::doSomething() below:

class Foo
{
   protected $bar;

   public function getBar()
   {
     return $this->bar;
   }

   public function setBar( $baz )
   {
     $this->bar = $baz;
   }

   // ...

   protected function doSomething()
   {
     $new_value = $this->getNewValue();

     $this->bar = $new_value;

     // OR

     $this->setBar( $new_value );
   }
}

Which is preferred, if either?

Thanks!

-- 
Yitzchak Schaffer
Systems Manager
Touro College Libraries
33 West 23rd Street
New York, NY 10010
Tel (212) 463-0400 x5230
Fax (212) 627-3197
Email yitzchak.schaffer at tourolib.org

Access Problems? Contact systems.library at touro.edu



More information about the talk mailing list