Re: Constructors with multiple methods

From: Date: Thu, 12 Apr 2007 04:58:55 +0000
Subject: Re: Constructors with multiple methods
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-252700@lists.php.net to get a copy of this message
Damien wrote:
Hi all, Say you may want to create an instance in multiple ways, such as creating from scratch or loading from a database. Is something like this normal for creating an instance?
I do this: class Foo { function Foo($id=0) {
    if (is_int($id) && (int)$id > 0) {
      return $this->Load($id);
    }
    // set default variables.
} } -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#252700) next »