Re: Raising errors inside a constructor

From: Date: Tue, 17 Aug 2004 20:11:43 +0000
Subject: Re: Raising errors inside a constructor
References: 1 2 3 4 5 6 7 8 9  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32750@lists.php.net to get a copy of this message
Olivier Guilyardi wrote:
Thank you for helping me understand that :) I must say all of these static calls on the ErrorStack introduction page confused me. 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();
} Greg

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