Re: Raising errors inside a constructor

From: Date: Wed, 18 Aug 2004 18:53:06 +0000
Subject: Re: Raising errors inside a constructor
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32757@lists.php.net to get a copy of this message
Greg Beaver wrote:
Olivier Guilyardi wrote:
Now, ErrorStack seems indeed powerful. I guess it's not too hard to make a base class that uses ErrorStack. Then I'd subclass it to be able to do the much more clearer : if ($berry->hasError()) , instead of this PEAR_ErrorStack::staticHasErrors('berry') thing that will confuse 90% of the people who read my code.
sub-classing is unnecessary. All you need to do is in the constructor add this line: $this->_stack = &PEAR_ErrorStack::singleton('berry'); And then you can write wrappers if you'd like. function hasError() {
    return $this->_stack->hasErrors();
}
That is very nice. Thanks ! -- og

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