Re: Raising errors inside a constructor
| From: | Hans L | Date: | Mon, 16 Aug 2004 22:06:14 +0000 |
| Subject: | Re: Raising errors inside a constructor | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32714@lists.php.net to get a copy of this message | ||
Olivier Guilyardi wrote:
Hans L wrote:Easiest way is to use it statically: // in class: $this->stack = &PEAR_ErrorStack::singleton('MyPackage'); ... $this->stack->push(...) // in calling code $mystack = &PEAR_ErrorStack::singleton('MyPackage'); ... if ($mystack->hasErrors()) {...} Of course you can always create a base class to do what you are suggesting but it seems like a bad idea w/o interface support (i.e. for PHP4). Unless all base classes extend your error handling class then you're going to have issues w/ multiple inheritance. This rather sounds like the "extends PEAR" syndrome. Why not simply use PEAR_ErrorStack statically? It gives you more control (e.g. you could have multiple stacks for a class) without using up your class inheritance options for such a simple bit of code. Perhaps I'm missing something; I definitely don't see the point of having all PEAR packages extend a base class just for the point of error handling -- particularly since this only applies to new PHP4 code, which I'm sure will be increasingly scarce. Of course *you* can do whatever you want in your development. It may make sense for your application to have a base class and certainly if you are using some common base class anyway, then refactoring shared functionality into a base class is good practice. I just wanted to point out that what you are describing is very much like what PEAR_ErrorStack does & figured that you should be aware of that before you spend time re-inventing it. If you've looked at it, cool. I've nothing more to say about it :) -HansOk, so what you have proposed is simply "why not use PEAR_ErrorStack for error handling". Of course you can do this! -- this is an official PEAR error handling option. It sounds like you haven't seen these docs: http://pear.php.net/manual/en/core.pear.pear-errorstack.intro.phpWell, I had read the ErrorStack introduction before posting in here. I've read it again. Please explain me how ErrorStack allows me to do this : <snip>