Reply to Re: [PHP] Best practices for set/get methods

Your name:

Reply:


Posted by Greg Donald on 10/07/33 11:13

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/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация