Re: upgrade to PEAR_ErrorStack for PEAR2?
| From: | Greg Beaver | Date: | Thu, 20 Sep 2007 05:08:49 +0000 |
| Subject: | Re: upgrade to PEAR_ErrorStack for PEAR2? | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-48088@lists.php.net to get a copy of this message | ||
Travis Swicegood wrote:
> I like it with one exception:
>
> On Sep 6, 2007, at 11:48 PM, Gregory Beaver wrote:
>
>> <?php
>> $multi = new PEAR2_Pyrus_MultiErrors;
>>
>> $multi[E_WARNING] = new PEAR2_MyPackage_Exception('whatever');
>> $multi[E_WARNING] = new PEAR2_MyPackage_Exception('another thing');
>> $multi[E_NOTICE] = new PEAR2_MyPackage_Exception('some small thing');
>> $multi[E_ERROR] = new PEAR2_MyPackage_Exception('big deal');
>> ?>
>
> No no no... :-)
>
> $multi[E_WARNING][] = new Exception();
> $multi[E_WARNING][] = new Exception();
>
> Doing the magic there is just confusing with no gain. You could change
> the API around a bit to determine which errors it would hold on to too
> which would help free up memory if a bunch of notices got thrown:
>
> $multi = new PEAR2_MultiErrors();
> $errorsOnly = new PEAR2_MultiErrors(E_ERROR);
>
> Basically, make the constructor take a similar parameter to
> error_reporting() and when nothing is given assume it wants to hold onto
> everything.
I haven't added this bit yet, but I have refactored it to work as:
$multi->E_WARNING[] = new Exception();
The filter is looser, so you can make up your own E_ levels:
$multi->E_WHATEVER[] = new Exception();
In terms of saving memory, this may happen, but is not likely to be a
big issue, as multierrors is most likely to be used inside a
method/class and freed upon exit, but it will be added if I can do it well.
Greg