Re: Best practices for set/get methods

From: Date: Thu, 14 Apr 2005 21:40:33 +0000
Subject: Re: Best practices for set/get methods
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-213121@lists.php.net to get a copy of this message
On 4/14/05, Tim Boring <tboring@adw1.com> wrote: > Does anyone have suggestions/ideas about best practices for writing > set/get methods in PHP5? There are two basic ways I've seen this done, > which I've provided examples of below. Method #2 is obviously the easier > way, but that doesn't mean it may be the best way. > > I'm curious to read people's responses. I would start off with a simple base class like this: abstract class Base { public function __construct() { } public function __destruct() { } public function __toString() { return '<pre>' . print_r( $this, TRUE ) . '</pre>'; } public function __get( $key ) { return isset( $this->$key ) ? $this->$key : NULL; } public function __set( $key, $value ) { $this->$key = $value; } } -- Greg Donald Zend Certified Engineer http://destiney.com/

« previous php.general (#213121) next »