Re: Raising errors inside a constructor

From: Date: Mon, 16 Aug 2004 02:44:55 +0000
Subject: Re: Raising errors inside a constructor
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32698@lists.php.net to get a copy of this message
Alan Knowles wrote:
I don't see the point with being forced to make factory methods, only because there's no way to raise an error from the constructor.
why not? It makes the code alot clearer. If you need a single contructor, That may return errrors.. I aways try and use: $x = y::construct(...)
Why a such ugly thing : $foo =& Foo::construct($options); if (PEAR::isError($foo)) { ... } when you could do : $foo = new Foo($options); if ($foo->hasError()) { ... } ? I don't think it makes anything clearer. My Idea was to make some base class provide this sort of features. See, class Foo extends SomeBaseClass. I must confess I thought about the PEAR base class itself... But, well, as Lukas stated, the most stylish is : try {
    $foo = new Foo($options);
} catch (InvalidOption $e) {
    ...
} -- og

« previous php.pear.dev (#32698) next »