Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-29 Thread Саша Стаменковић
Thanks.
I'm satisfied with just logging all warnings...so I can fix them during
development and always track them in my custom log on production since I
don't have access to php error log on my shared hosting :)

Regards,
Saša Stamenković


On Tue, Sep 29, 2009 at 9:56 AM, drm  wrote:

> Hi Saša,
>
>
> Basically, if the exception isn't thrown within the dispatch loop, you
> would have to catch the exception in your index.php and dispatch to your
> error controller yourself. To make sure your errors and notices etc are
> thrown as exceptions you would need an error handler like mine.
>
> Roughly something like this:
>
> try {
>  $front->dispatch(); // (or $app->bootstrap()->run())
> }catch(Exception $e) {
>  $request = new Zend_Controller_Request_Simple('error', 'error');
>  $front->dispatch($request);
> }
>
> Maybe you would need to reset the dispatcher, but best way to find out it's
> been done is read the source code of the Zend_Controller_Plugin_ErrorHandler
>
> But still, I'd advise against it and handle errors at this level without
> your error controller, because it is quite possible the error will come up
> just another time in the catch() block, and you would still have to catch
> that one and handle it. You would of course want to eliminate every
> possibility your error handler itself is faulty.
>
>
> drm / Gerard
>
>
> Саша Стаменковић wrote:
>
>> Thx. But I can't see how this can help :P
>>
>> Regards,
>> Saša Stamenković
>>
>>
>> On Thu, Sep 24, 2009 at 3:00 PM, Vincent de Lau > vinc...@delau.nl>> wrote:
>>
>>> What i did was writing a function that simply throws an
>>exception and
>>> passing that function to set_error_handler, something like this:
>>>
>>> error_reporting(E_ALL);
>>> function exceptionThrower($type, $errMsg, $errFile, $errLine) {
>>> throw new Exception($errMsg);
>>> }
>>> set_error_handler('exceptionThrower');
>>
>>You should check out: http://php.net/ErrorException
>>
>>It is an Exception type tailored to PHP's errors.
>>
>>Vincent de Lau
>> vinc...@delau.nl 
>>
>>
>>
>


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-29 Thread drm

Hi Saša,


Basically, if the exception isn't thrown within the dispatch loop, you 
would have to catch the exception in your index.php and dispatch to your 
error controller yourself. To make sure your errors and notices etc are 
thrown as exceptions you would need an error handler like mine.


Roughly something like this:

try {
  $front->dispatch(); // (or $app->bootstrap()->run())
}catch(Exception $e) {
  $request = new Zend_Controller_Request_Simple('error', 'error');
  $front->dispatch($request);
}

Maybe you would need to reset the dispatcher, but best way to find out 
it's been done is read the source code of the 
Zend_Controller_Plugin_ErrorHandler


But still, I'd advise against it and handle errors at this level without 
your error controller, because it is quite possible the error will come 
up just another time in the catch() block, and you would still have to 
catch that one and handle it. You would of course want to eliminate 
every possibility your error handler itself is faulty.



drm / Gerard


Саша Стаменковић wrote:

Thx. But I can't see how this can help :P

Regards,
Saša Stamenković


On Thu, Sep 24, 2009 at 3:00 PM, Vincent de Lau > wrote:


> What i did was writing a function that simply throws an
exception and
> passing that function to set_error_handler, something like this:
>
> error_reporting(E_ALL);
> function exceptionThrower($type, $errMsg, $errFile, $errLine) {
> throw new Exception($errMsg);
> }
> set_error_handler('exceptionThrower');

You should check out: http://php.net/ErrorException

It is an Exception type tailored to PHP's errors.

Vincent de Lau
 vinc...@delau.nl 






Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
Man, this really works. Thanks :)

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 2:03 PM, Karol Grecki  wrote:

>
> You need to check that in order to ignore suppressed errors. I gave you
> working code that does exactly what you want. I suggest you use it. You can
> always change it later once you understand how it works.
>
> Karol
>
>
> umpirsky wrote:
> >
> > But I want to catch errors that are not suppressed with @. If I check if
> > error reporting is on, I will catch all of them or no one.
> >
> > Regards,
> > Saša Stamenković
> >
> >
> > On Mon, Sep 28, 2009 at 1:36 PM, Karol Grecki  wrote:
> >
> >>
> >> There's answer for it in the code sample I gave you.
> >> Error handler will intercept all errors even if they were silenced with
> @
> >> operator.
> >> You need to check if error reporting is disabled at the time the error
> >> happens.
> >>
> >> Karol
> >>
> >>
> >> umpirsky wrote:
> >> >
> >> > Now I get a lot of crap catched :)
> >> > For example:
> >> >
> >> >
> >>
> fopen(/mnt/home/sasas/www/auto/application/controllers/ImagesController.php)
> >> > [ function.fopen function.fopen ]: failed to open stream: No
> >> > such file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> >> > which is ok, but this:
> >> >
> >> >
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php)
> >> [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php)
> >> [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> >> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormSelect.php)
> >> [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> >> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
> >> [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> >> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
> >> [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> >> > function.fopen function.fopen ]: failed to open stream: No such
> >> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >> >
> >> > which is strange, why loader looks for helpers in my helpers path, and
> >> not
> >> > in zf library first?
> >> >
> >> > Regards,
> >> > Saša Stamenković
> >> >
> >> >
> >> > On Mon, Sep 28, 2009 at 1:08 PM, Саша Стаменковић
> >> > wrote:
> >> >
> >> >> Nice answer Grecki, thanks.
> >> >> require_once 'controllers/ErrorController.php';
> >> >> set_error_handler(array('ErrorController', 'phpError'));
> >> >>
> >> >> fixed problem. Strange :)
> >> >>
> >> >> Regards,
> >> >> Saša Stamenković
> >> >>
> >> >>
> >> >>
> >> >> On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki 
> >> wrote:
> >> >>
> >> >>>
> >> >>> If you named your functions differently you need to modify the code
> >> >>> accordingly.
> >> >>> Also, make sure that this class is actually loaded or can be loaded
> >> with
> >> >>> autoloader before you try to use it and register the error handler.
> >> >>>
> >> >>> Regards
> >> >>> Karol
> >> >>>
> >> >>>
> >> >>>
> >> >>> umpirsky wrote:
> >> >>> >
> >> >>> > *Warning*: set_error_handler() expects the argument
> >> >>> > (ErrorController::phpError) to be a valid callback in *
> >> >>> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
> >> >>> >
> >> >>> > Regards,
> >> >>> > Saša Stamenković
> >> >>> >
> >> >>> >
> >> >>> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki  >
> >> >>> wrote:
> >> >>> >
> >> >>> >>
> >> >>> >> Try this, it works for me.
> >> >>> >>
> >> >>> >> class X_Error_Handler
> >> >>> >> {
> >> >>> >>public static function handle($errno, $errstr, $errfile,
> >> $errline)
> >> >>> >>{
> >> >>> >>//this allows error suppression in 3rd party code to work
> >> >>> >>if (!error_reporting()) return;
> 

Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Karol Grecki

You need to check that in order to ignore suppressed errors. I gave you
working code that does exactly what you want. I suggest you use it. You can
always change it later once you understand how it works.

Karol


umpirsky wrote:
> 
> But I want to catch errors that are not suppressed with @. If I check if
> error reporting is on, I will catch all of them or no one.
> 
> Regards,
> Saša Stamenković
> 
> 
> On Mon, Sep 28, 2009 at 1:36 PM, Karol Grecki  wrote:
> 
>>
>> There's answer for it in the code sample I gave you.
>> Error handler will intercept all errors even if they were silenced with @
>> operator.
>> You need to check if error reporting is disabled at the time the error
>> happens.
>>
>> Karol
>>
>>
>> umpirsky wrote:
>> >
>> > Now I get a lot of crap catched :)
>> > For example:
>> >
>> >
>> fopen(/mnt/home/sasas/www/auto/application/controllers/ImagesController.php)
>> > [ function.fopen function.fopen ]: failed to open stream: No
>> > such file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> >
>> > which is ok, but this:
>> >
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php)
>> [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php)
>> [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> >
>> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormSelect.php)
>> [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> >
>> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
>> [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> >
>> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
>> [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
>> > function.fopen function.fopen ]: failed to open stream: No such
>> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
>> >
>> > which is strange, why loader looks for helpers in my helpers path, and
>> not
>> > in zf library first?
>> >
>> > Regards,
>> > Saša Stamenković
>> >
>> >
>> > On Mon, Sep 28, 2009 at 1:08 PM, Саша Стаменковић
>> > wrote:
>> >
>> >> Nice answer Grecki, thanks.
>> >> require_once 'controllers/ErrorController.php';
>> >> set_error_handler(array('ErrorController', 'phpError'));
>> >>
>> >> fixed problem. Strange :)
>> >>
>> >> Regards,
>> >> Saša Stamenković
>> >>
>> >>
>> >>
>> >> On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki 
>> wrote:
>> >>
>> >>>
>> >>> If you named your functions differently you need to modify the code
>> >>> accordingly.
>> >>> Also, make sure that this class is actually loaded or can be loaded
>> with
>> >>> autoloader before you try to use it and register the error handler.
>> >>>
>> >>> Regards
>> >>> Karol
>> >>>
>> >>>
>> >>>
>> >>> umpirsky wrote:
>> >>> >
>> >>> > *Warning*: set_error_handler() expects the argument
>> >>> > (ErrorController::phpError) to be a valid callback in *
>> >>> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
>> >>> >
>> >>> > Regards,
>> >>> > Saša Stamenković
>> >>> >
>> >>> >
>> >>> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki 
>> >>> wrote:
>> >>> >
>> >>> >>
>> >>> >> Try this, it works for me.
>> >>> >>
>> >>> >> class X_Error_Handler
>> >>> >> {
>> >>> >>public static function handle($errno, $errstr, $errfile,
>> $errline)
>> >>> >>{
>> >>> >>//this allows error suppression in 3rd party code to work
>> >>> >>if (!error_reporting()) return;
>> >>> >>
>> >>> >>throw new X_RuntimeException($errstr . " in
>> >>> $errfile:$errline",
>> >>> >> $errno);
>> >>> >>}
>> >>> >>
>> >>> >>public static function set()
>> >>> >>{
>> >>> >>set_error_handler(array(__CLASS__, 'handle'));
>> >>> >>}
>> >>> >> }
>> >>> >>
>> >>> >> Then you call X_Error_Handler::set() in your bootstrap and built
>> in
>> >>> php
>> 

Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
But I want to catch errors that are not suppressed with @. If I check if
error reporting is on, I will catch all of them or no one.

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 1:36 PM, Karol Grecki  wrote:

>
> There's answer for it in the code sample I gave you.
> Error handler will intercept all errors even if they were silenced with @
> operator.
> You need to check if error reporting is disabled at the time the error
> happens.
>
> Karol
>
>
> umpirsky wrote:
> >
> > Now I get a lot of crap catched :)
> > For example:
> >
> >
> fopen(/mnt/home/sasas/www/auto/application/controllers/ImagesController.php)
> > [ function.fopen function.fopen ]: failed to open stream: No
> > such file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >
> > which is ok, but this:
> >
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormSelect.php)
> [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
> [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php)
> [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> > fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> > function.fopen function.fopen ]: failed to open stream: No such
> > file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> >
> > which is strange, why loader looks for helpers in my helpers path, and
> not
> > in zf library first?
> >
> > Regards,
> > Saša Stamenković
> >
> >
> > On Mon, Sep 28, 2009 at 1:08 PM, Саша Стаменковић
> > wrote:
> >
> >> Nice answer Grecki, thanks.
> >> require_once 'controllers/ErrorController.php';
> >> set_error_handler(array('ErrorController', 'phpError'));
> >>
> >> fixed problem. Strange :)
> >>
> >> Regards,
> >> Saša Stamenković
> >>
> >>
> >>
> >> On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki 
> wrote:
> >>
> >>>
> >>> If you named your functions differently you need to modify the code
> >>> accordingly.
> >>> Also, make sure that this class is actually loaded or can be loaded
> with
> >>> autoloader before you try to use it and register the error handler.
> >>>
> >>> Regards
> >>> Karol
> >>>
> >>>
> >>>
> >>> umpirsky wrote:
> >>> >
> >>> > *Warning*: set_error_handler() expects the argument
> >>> > (ErrorController::phpError) to be a valid callback in *
> >>> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
> >>> >
> >>> > Regards,
> >>> > Saša Stamenković
> >>> >
> >>> >
> >>> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki 
> >>> wrote:
> >>> >
> >>> >>
> >>> >> Try this, it works for me.
> >>> >>
> >>> >> class X_Error_Handler
> >>> >> {
> >>> >>public static function handle($errno, $errstr, $errfile,
> $errline)
> >>> >>{
> >>> >>//this allows error suppression in 3rd party code to work
> >>> >>if (!error_reporting()) return;
> >>> >>
> >>> >>throw new X_RuntimeException($errstr . " in
> >>> $errfile:$errline",
> >>> >> $errno);
> >>> >>}
> >>> >>
> >>> >>public static function set()
> >>> >>{
> >>> >>set_error_handler(array(__CLASS__, 'handle'));
> >>> >>}
> >>> >> }
> >>> >>
> >>> >> Then you call X_Error_Handler::set() in your bootstrap and built in
> >>> php
> >>> >> errors will bubble up to error controller as exceptions.
> >>> >> Bear in mind there are some limitation to it, like fatal errors
> >>> cannot
> >>> be
> >>> >> handled this way and not everything can be captured in the error
> >>> >> controller.
> >>> >> You need a try-catch block around your whole dispatch loop to catch
> >>> >> errors
> >>> >> in plugins etc.
> >>> >>
> >>> >> Regards

Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Karol Grecki

There's answer for it in the code sample I gave you.
Error handler will intercept all errors even if they were silenced with @
operator.
You need to check if error reporting is disabled at the time the error
happens.

Karol


umpirsky wrote:
> 
> Now I get a lot of crap catched :)
> For example:
> 
> fopen(/mnt/home/sasas/www/auto/application/controllers/ImagesController.php)
> [ function.fopen function.fopen ]: failed to open stream: No
> such file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> 
> which is ok, but this:
> 
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormSelect.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [
> function.fopen function.fopen ]: failed to open stream: No such
> file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
> 
> which is strange, why loader looks for helpers in my helpers path, and not
> in zf library first?
> 
> Regards,
> Saša Stamenković
> 
> 
> On Mon, Sep 28, 2009 at 1:08 PM, Саша Стаменковић
> wrote:
> 
>> Nice answer Grecki, thanks.
>> require_once 'controllers/ErrorController.php';
>> set_error_handler(array('ErrorController', 'phpError'));
>>
>> fixed problem. Strange :)
>>
>> Regards,
>> Saša Stamenković
>>
>>
>>
>> On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki  wrote:
>>
>>>
>>> If you named your functions differently you need to modify the code
>>> accordingly.
>>> Also, make sure that this class is actually loaded or can be loaded with
>>> autoloader before you try to use it and register the error handler.
>>>
>>> Regards
>>> Karol
>>>
>>>
>>>
>>> umpirsky wrote:
>>> >
>>> > *Warning*: set_error_handler() expects the argument
>>> > (ErrorController::phpError) to be a valid callback in *
>>> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
>>> >
>>> > Regards,
>>> > Saša Stamenković
>>> >
>>> >
>>> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki 
>>> wrote:
>>> >
>>> >>
>>> >> Try this, it works for me.
>>> >>
>>> >> class X_Error_Handler
>>> >> {
>>> >>public static function handle($errno, $errstr, $errfile, $errline)
>>> >>{
>>> >>//this allows error suppression in 3rd party code to work
>>> >>if (!error_reporting()) return;
>>> >>
>>> >>throw new X_RuntimeException($errstr . " in
>>> $errfile:$errline",
>>> >> $errno);
>>> >>}
>>> >>
>>> >>public static function set()
>>> >>{
>>> >>set_error_handler(array(__CLASS__, 'handle'));
>>> >>}
>>> >> }
>>> >>
>>> >> Then you call X_Error_Handler::set() in your bootstrap and built in
>>> php
>>> >> errors will bubble up to error controller as exceptions.
>>> >> Bear in mind there are some limitation to it, like fatal errors
>>> cannot
>>> be
>>> >> handled this way and not everything can be captured in the error
>>> >> controller.
>>> >> You need a try-catch block around your whole dispatch loop to catch
>>> >> errors
>>> >> in plugins etc.
>>> >>
>>> >> Regards
>>> >> Karol
>>> >>
>>> >>
>>> >> umpirsky wrote:
>>> >> >
>>> >> > I'm trying to do this with set_error_handler(), my will is to
>>> trigger
>>> >> > Error
>>> >> > controller and catch this as application error, since I want to log
>>> all
>>> >> > errors in one place - Error controller.
>>> >> > I tried with setting error handler in bootstrap to function in
>>> >> index.php
>>> >> > and
>>> >> > that function calls error controller statically, but no success.
>>> There
>>

Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
Now I get a lot of crap catched :)
For example:

fopen(/mnt/home/sasas/www/auto/application/controllers/ImagesController.php)
[function.fopen]: failed to open stream: No
such file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.

which is ok, but this:

fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormLabel.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormSelect.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/FormButton.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/Form.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.
fopen(/mnt/home/sasas/www/auto/application/views/helpers/Layout.php) [function.fopen]: failed to open stream: No such
file or directory in /mnt/home/sasas/www/Zend/Loader.php #165.

which is strange, why loader looks for helpers in my helpers path, and not
in zf library first?

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 1:08 PM, Саша Стаменковић wrote:

> Nice answer Grecki, thanks.
> require_once 'controllers/ErrorController.php';
> set_error_handler(array('ErrorController', 'phpError'));
>
> fixed problem. Strange :)
>
> Regards,
> Saša Stamenković
>
>
>
> On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki  wrote:
>
>>
>> If you named your functions differently you need to modify the code
>> accordingly.
>> Also, make sure that this class is actually loaded or can be loaded with
>> autoloader before you try to use it and register the error handler.
>>
>> Regards
>> Karol
>>
>>
>>
>> umpirsky wrote:
>> >
>> > *Warning*: set_error_handler() expects the argument
>> > (ErrorController::phpError) to be a valid callback in *
>> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
>> >
>> > Regards,
>> > Saša Stamenković
>> >
>> >
>> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki 
>> wrote:
>> >
>> >>
>> >> Try this, it works for me.
>> >>
>> >> class X_Error_Handler
>> >> {
>> >>public static function handle($errno, $errstr, $errfile, $errline)
>> >>{
>> >>//this allows error suppression in 3rd party code to work
>> >>if (!error_reporting()) return;
>> >>
>> >>throw new X_RuntimeException($errstr . " in $errfile:$errline",
>> >> $errno);
>> >>}
>> >>
>> >>public static function set()
>> >>{
>> >>set_error_handler(array(__CLASS__, 'handle'));
>> >>}
>> >> }
>> >>
>> >> Then you call X_Error_Handler::set() in your bootstrap and built in php
>> >> errors will bubble up to error controller as exceptions.
>> >> Bear in mind there are some limitation to it, like fatal errors cannot
>> be
>> >> handled this way and not everything can be captured in the error
>> >> controller.
>> >> You need a try-catch block around your whole dispatch loop to catch
>> >> errors
>> >> in plugins etc.
>> >>
>> >> Regards
>> >> Karol
>> >>
>> >>
>> >> umpirsky wrote:
>> >> >
>> >> > I'm trying to do this with set_error_handler(), my will is to trigger
>> >> > Error
>> >> > controller and catch this as application error, since I want to log
>> all
>> >> > errors in one place - Error controller.
>> >> > I tried with setting error handler in bootstrap to function in
>> >> index.php
>> >> > and
>> >> > that function calls error controller statically, but no success.
>> There
>> >> > must
>> >> > be some easy way to do this.
>> >> >
>> >> > Anyone know?
>> >> >
>> >> > Regards,
>> >> > Saša Stamenković
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
>> >> Sent from the Zend Framework mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643850.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>

Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
Nice answer Grecki, thanks.
require_once 'controllers/ErrorController.php';
set_error_handler(array('ErrorController', 'phpError'));

fixed problem. Strange :)

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 1:03 PM, Karol Grecki  wrote:

>
> If you named your functions differently you need to modify the code
> accordingly.
> Also, make sure that this class is actually loaded or can be loaded with
> autoloader before you try to use it and register the error handler.
>
> Regards
> Karol
>
>
>
> umpirsky wrote:
> >
> > *Warning*: set_error_handler() expects the argument
> > (ErrorController::phpError) to be a valid callback in *
> > /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
> >
> > Regards,
> > Saša Stamenković
> >
> >
> > On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki 
> wrote:
> >
> >>
> >> Try this, it works for me.
> >>
> >> class X_Error_Handler
> >> {
> >>public static function handle($errno, $errstr, $errfile, $errline)
> >>{
> >>//this allows error suppression in 3rd party code to work
> >>if (!error_reporting()) return;
> >>
> >>throw new X_RuntimeException($errstr . " in $errfile:$errline",
> >> $errno);
> >>}
> >>
> >>public static function set()
> >>{
> >>set_error_handler(array(__CLASS__, 'handle'));
> >>}
> >> }
> >>
> >> Then you call X_Error_Handler::set() in your bootstrap and built in php
> >> errors will bubble up to error controller as exceptions.
> >> Bear in mind there are some limitation to it, like fatal errors cannot
> be
> >> handled this way and not everything can be captured in the error
> >> controller.
> >> You need a try-catch block around your whole dispatch loop to catch
> >> errors
> >> in plugins etc.
> >>
> >> Regards
> >> Karol
> >>
> >>
> >> umpirsky wrote:
> >> >
> >> > I'm trying to do this with set_error_handler(), my will is to trigger
> >> > Error
> >> > controller and catch this as application error, since I want to log
> all
> >> > errors in one place - Error controller.
> >> > I tried with setting error handler in bootstrap to function in
> >> index.php
> >> > and
> >> > that function calls error controller statically, but no success. There
> >> > must
> >> > be some easy way to do this.
> >> >
> >> > Anyone know?
> >> >
> >> > Regards,
> >> > Saša Stamenković
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643850.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Karol Grecki

If you named your functions differently you need to modify the code
accordingly.
Also, make sure that this class is actually loaded or can be loaded with
autoloader before you try to use it and register the error handler.

Regards
Karol



umpirsky wrote:
> 
> *Warning*: set_error_handler() expects the argument
> (ErrorController::phpError) to be a valid callback in *
> /mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*
> 
> Regards,
> Saša Stamenković
> 
> 
> On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki  wrote:
> 
>>
>> Try this, it works for me.
>>
>> class X_Error_Handler
>> {
>>public static function handle($errno, $errstr, $errfile, $errline)
>>{
>>//this allows error suppression in 3rd party code to work
>>if (!error_reporting()) return;
>>
>>throw new X_RuntimeException($errstr . " in $errfile:$errline",
>> $errno);
>>}
>>
>>public static function set()
>>{
>>set_error_handler(array(__CLASS__, 'handle'));
>>}
>> }
>>
>> Then you call X_Error_Handler::set() in your bootstrap and built in php
>> errors will bubble up to error controller as exceptions.
>> Bear in mind there are some limitation to it, like fatal errors cannot be
>> handled this way and not everything can be captured in the error
>> controller.
>> You need a try-catch block around your whole dispatch loop to catch
>> errors
>> in plugins etc.
>>
>> Regards
>> Karol
>>
>>
>> umpirsky wrote:
>> >
>> > I'm trying to do this with set_error_handler(), my will is to trigger
>> > Error
>> > controller and catch this as application error, since I want to log all
>> > errors in one place - Error controller.
>> > I tried with setting error handler in bootstrap to function in
>> index.php
>> > and
>> > that function calls error controller statically, but no success. There
>> > must
>> > be some easy way to do this.
>> >
>> > Anyone know?
>> >
>> > Regards,
>> > Saša Stamenković
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643850.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
No, I have phpError static method
in ErrorController, set_error_handler(array('ErrorController', 'phpError'));
calls it staticly, not through MVC, right?

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 12:57 PM, till  wrote:

> On Mon, Sep 28, 2009 at 12:54 PM, Саша Стаменковић 
> wrote:
> > Warning: set_error_handler() expects the argument
> > (ErrorController::phpError) to be a valid callback in
> > /mnt/home/sasas/www/auto/application/Bootstrap.php on line 16
>
> You probably need phpErrorAction() ?
>
> Till
>


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread till
On Mon, Sep 28, 2009 at 12:54 PM, Саша Стаменковић  wrote:
> Warning: set_error_handler() expects the argument
> (ErrorController::phpError) to be a valid callback in
> /mnt/home/sasas/www/auto/application/Bootstrap.php on line 16

You probably need phpErrorAction() ?

Till


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Саша Стаменковић
*Warning*: set_error_handler() expects the argument
(ErrorController::phpError) to be a valid callback in *
/mnt/home/sasas/www/auto/application/Bootstrap.php* on line *16*

Regards,
Saša Stamenković


On Mon, Sep 28, 2009 at 12:29 PM, Karol Grecki  wrote:

>
> Try this, it works for me.
>
> class X_Error_Handler
> {
>public static function handle($errno, $errstr, $errfile, $errline)
>{
>//this allows error suppression in 3rd party code to work
>if (!error_reporting()) return;
>
>throw new X_RuntimeException($errstr . " in $errfile:$errline",
> $errno);
>}
>
>public static function set()
>{
>set_error_handler(array(__CLASS__, 'handle'));
>}
> }
>
> Then you call X_Error_Handler::set() in your bootstrap and built in php
> errors will bubble up to error controller as exceptions.
> Bear in mind there are some limitation to it, like fatal errors cannot be
> handled this way and not everything can be captured in the error
> controller.
> You need a try-catch block around your whole dispatch loop to catch errors
> in plugins etc.
>
> Regards
> Karol
>
>
> umpirsky wrote:
> >
> > I'm trying to do this with set_error_handler(), my will is to trigger
> > Error
> > controller and catch this as application error, since I want to log all
> > errors in one place - Error controller.
> > I tried with setting error handler in bootstrap to function in index.php
> > and
> > that function calls error controller statically, but no success. There
> > must
> > be some easy way to do this.
> >
> > Anyone know?
> >
> > Regards,
> > Saša Stamenković
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-28 Thread Karol Grecki

Try this, it works for me.

class X_Error_Handler
{
public static function handle($errno, $errstr, $errfile, $errline)
{
//this allows error suppression in 3rd party code to work
if (!error_reporting()) return;

throw new X_RuntimeException($errstr . " in $errfile:$errline",
$errno);
}

public static function set()
{
set_error_handler(array(__CLASS__, 'handle'));
}
}

Then you call X_Error_Handler::set() in your bootstrap and built in php
errors will bubble up to error controller as exceptions.
Bear in mind there are some limitation to it, like fatal errors cannot be
handled this way and not everything can be captured in the error controller.
You need a try-catch block around your whole dispatch loop to catch errors
in plugins etc.

Regards
Karol


umpirsky wrote:
> 
> I'm trying to do this with set_error_handler(), my will is to trigger
> Error
> controller and catch this as application error, since I want to log all
> errors in one place - Error controller.
> I tried with setting error handler in bootstrap to function in index.php
> and
> that function calls error controller statically, but no success. There
> must
> be some easy way to do this.
> 
> Anyone know?
> 
> Regards,
> Saša Stamenković
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-24 Thread Саша Стаменковић
Thx. But I can't see how this can help :P

Regards,
Saša Stamenković


On Thu, Sep 24, 2009 at 3:00 PM, Vincent de Lau  wrote:

> > What i did was writing a function that simply throws an exception and
> > passing that function to set_error_handler, something like this:
> >
> > error_reporting(E_ALL);
> > function exceptionThrower($type, $errMsg, $errFile, $errLine) {
> > throw new Exception($errMsg);
> > }
> > set_error_handler('exceptionThrower');
>
> You should check out: http://php.net/ErrorException
>
> It is an Exception type tailored to PHP's errors.
>
> Vincent de Lau
>  vinc...@delau.nl
>
>


RE: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-24 Thread Vincent de Lau
> What i did was writing a function that simply throws an exception and
> passing that function to set_error_handler, something like this:
> 
> error_reporting(E_ALL);
> function exceptionThrower($type, $errMsg, $errFile, $errLine) {
> throw new Exception($errMsg);
> }
> set_error_handler('exceptionThrower');

You should check out: http://php.net/ErrorException

It is an Exception type tailored to PHP's errors.

Vincent de Lau
 vinc...@delau.nl



Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-24 Thread Саша Стаменковић
Thx, thats ok, but is there any way to trap error in ErrorController, maybe
redirect to /error, but then you need to pass error msg through url...messy
:)

Regards,
Saša Stamenković


On Thu, Sep 24, 2009 at 2:33 PM, drm  wrote:

> Hi,
>
> What i did was writing a function that simply throws an exception and
> passing that function to set_error_handler, something like this:
>
> error_reporting(E_ALL);
> function exceptionThrower($type, $errMsg, $errFile, $errLine) {
>   throw new Exception($errMsg);
> }
> set_error_handler('exceptionThrower');
>
> try {
>   echo $a['b'];
> } catch ( Exception $e ) {
>   echo "Sorry: ", $e->getMessage();
> }
>
> Only trouble with the errorcontroller is that it only catches the
> exceptions inside the dispatch loop, so I disabled that and put a try /
> catch around the entire bootstrap/dispatch and handle the exceptions myself,
> so I can easily implement 401 / 403 / 404 / 500 response codes based on the
> type of exception, no matter if it is thrown within the dispatch loop.
>
> drm / Gerard
>
>
>
> Саша Стаменковић wrote:
>
>> I'm trying to do this with set_error_handler(), my will is to trigger
>> Error controller and catch this as application error, since I want to log
>> all errors in one place - Error controller.
>> I tried with setting error handler in bootstrap to function in index.php
>> and that function calls error controller statically, but no success. There
>> must be some easy way to do this.
>>
>> Anyone know?
>>
>> Regards,
>> Saša Stamenković
>>
>
>


Re: [fw-general] Turn PHP errors/warnings/notices into exceptions

2009-09-24 Thread drm

Hi,

What i did was writing a function that simply throws an exception and 
passing that function to set_error_handler, something like this:


error_reporting(E_ALL);
function exceptionThrower($type, $errMsg, $errFile, $errLine) {
   throw new Exception($errMsg);
}
set_error_handler('exceptionThrower');

try {
   echo $a['b'];
} catch ( Exception $e ) {
   echo "Sorry: ", $e->getMessage();
}

Only trouble with the errorcontroller is that it only catches the 
exceptions inside the dispatch loop, so I disabled that and put a try / 
catch around the entire bootstrap/dispatch and handle the exceptions 
myself, so I can easily implement 401 / 403 / 404 / 500 response codes 
based on the type of exception, no matter if it is thrown within the 
dispatch loop.


drm / Gerard


Саша Стаменковић wrote:
I'm trying to do this with set_error_handler(), my will is to trigger 
Error controller and catch this as application error, since I want to 
log all errors in one place - Error controller. 

I tried with setting error handler in bootstrap to function in 
index.php and that function calls error controller statically, but no 
success. There must be some easy way to do this.


Anyone know?

Regards,
Saša Stamenković