Re: [PHP] Constructors with multiple methods

2007-04-11 Thread Chris
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

Re: [PHP] Constructors with multiple methods

2007-04-11 Thread Jarrel Cobb
"creating from scratch or loading from a database" sounds like you want a registry or service locator. Otherwise, you should encapsulate object instantiation in factory methods/classes On 4/11/07, Damien <[EMAIL PROTECTED]> wrote: Hi all, Say you may want to create an instance in multiple way

[PHP] Constructors with multiple methods

2007-04-11 Thread Damien
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? class Foo { function Foo($method) { switch ($method) { default: $method = 'create'; case '