|
Posted by Marcin Dobrucki on 09/16/05 15:37
www.douglassdavis.com wrote:
> lets say i have a class
> class Thing
> {
> function __construct($string)
> {
> // initialize by string
> }
> }
....
> What would be appropriate here?
I am not sure about appropriate, but you could try something like this:
class Foo {
function Foo($id) {
$this->setId($id);
$this->initialize();
}
function initialize() {
...
}
}
I usually do it so that inside the constructor, I do things that are
very unlikely to fail (eg. set constants, etc), and then defer stuff
that can fail (eg. getting stuff from DB, etc), to the initalizing
function.
Constructors are nice, coz then you can "$foo = new Object()". :)
/m
Navigation:
[Reply to this message]
|