|
Posted by Oli Filth on 09/16/05 20:32
Marcin Dobrucki said the following on 16/09/2005 13: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.
>
What? How does that help?
If initialize() "fails" then the constructor has still "failed"...
--
Oli
Navigation:
[Reply to this message]
|