Raising errors inside a constructor

From: Date: Sun, 15 Aug 2004 21:31:42 +0000
Subject: Raising errors inside a constructor
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32694@lists.php.net to get a copy of this message
Hi, Since it's not possible to return a PEAR_Error from a constructor, what about the following : class Foo extends Some_Error_Handling_Class {
    function Foo($bar)
    {
if(!$bar) {
	    $this->raiseError("Foo needs Bar");
        }
    }
} $foo = new Foo(0); if ($foo->hasError()) {
    echo $foo->popError();
} 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. What do you think of these inherited methods : hasError() and popError() ? -- og

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