# More valuable error message handling

- Thread: https://externals.io/message/24328
- Original archive: https://news-web.php.net/php.internals/24328
- Started by Michael Wallner on 2006-07-11T10:35:09+00:00
- Messages: 17
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #24328 — Michael Wallner — 2006-07-11T10:35:09+00:00

URL: https://externals.io/message/24328#24328

Hi,

I think many people agree that PHPs means for a developer to
get the last error message(s) are way suboptimal.

INI(track_errors) and $php_errormsg or hacking some error
handler magic are--despite sep. extension facilities--the
only one that come to mind, both cumbersome and unintuitive.


I therefore propose some new functionality with possibly
this 3 new functions:

- `error_get_last()`
 Get the last error message.

- error_get_all()
 Get an array of all occurred errors.

- error_clear_all()
 Reset error stack.

Return values and parameters are subject to discussion, as well as
when PHP puts errors into this stack, eventually if track_errors is
enabled?


Thoughts, objections, flames?



PS: Sorry, if that comes through twice.

Regards,
-- 
Michael

---

## #24329 — Lukas Smith — 2006-07-11T10:38:17+00:00

URL: https://externals.io/message/24328#24329 · In reply to: #24328

Michael Wallner wrote:

> - `error_get_last()`
> Get the last error message.

my wish would be that this one should work even if track_errors is not 
enabled.

regards,
Lukas

---

## #24330 — Antony Dovgal — 2006-07-11T10:53:55+00:00

URL: https://externals.io/message/24328#24330 · In reply to: #24329

> Michael Wallner wrote:
> 
> > […]
> 
> my wish would be that this one should work even if track_errors is not 
> enabled.

Yes, these functions should not depend on any INI directives.

-- 
Wbr, 
Antony Dovgal

---

## #24334 — Michael Wallner — 2006-07-11T14:53:04+00:00

URL: https://externals.io/message/24328#24334 · In reply to: #24328

I wrote:

> I therefore propose some new functionality with possibly
> this 3 new functions:
> 
> - `error_get_last()`
> Get the last error message.
> 
> - error_get_all()
> Get an array of all occurred errors.
> 
> - error_clear_all()
> Reset error stack.

Patch against 5_2:
http://dev.iworks.at/PATCHES/errorstack.diff.txt

Regards,
-- 
Michael

---

## #24336 — Michael Wallner — 2006-07-11T15:21:09+00:00

URL: https://externals.io/message/24328#24336 · In reply to: #24330

Antony Dovgal wrote:
> 
> > […]
> 
> Yes, these functions should not depend on any INI directives.

I'm with Ilia and think that there should be the possibility to
disable this and track_errors seems like the perfect and already
existing fit.

Regards,
-- 
Michael

---

## #24338 — Michael Vergoz — 2006-07-11T16:08:11+00:00

URL: https://externals.io/message/24328#24338 · In reply to: #24334

Hi Mike

For me +1 :)
I just have to look at something because i found a mem-leak where you patch 
(near)
I will write a mail soon

Mv-

-----Original Message ----- 
From: "Michael Wallner" <mike@php.net>
To: <internals@lists.php.net>
Sent: Tuesday, July 11, 2006 4:53 PM
Subject: [PHP-DEV] Re: More valuable error message handling


>I wrote:
>
> > […]
>
> Patch against 5_2:
> http://dev.iworks.at/PATCHES/errorstack.diff.txt
>
> Regards,
> -- 
> Michael

---

## #24344 — Marcus Boerger — 2006-07-11T18:39:09+00:00

URL: https://externals.io/message/24328#24344 · In reply to: #24336

Hello Michael,

  yep, here too. track_errors is an optimizations when you don't
want to debug but simply use your app.

best regards
marcus

Tuesday, July 11, 2006, 5:21:09 PM, you wrote:

> Antony Dovgal wrote:
> > […]

> I'm with Ilia and think that there should be the possibility to
> disable this and track_errors seems like the perfect and already
> existing fit.

> Regards,
> -- 
> Michael




Best regards,
 Marcus

---

## #24347 — Lukas Smith — 2006-07-11T21:17:12+00:00

URL: https://externals.io/message/24328#24347 · In reply to: #24344

Marcus Boerger wrote:
> Hello Michael,
> 
>   yep, here too. track_errors is an optimizations when you don't
> want to debug but simply use your app.

thats why i said that i would like to atleast be able to get the last 
error without having to mess/check track_errors ini setting. i think 
this is an acceptable compromise to always store the last error, no?

this covers 100% of all use cases i ever had where i would mess with the 
track_errors setting at runtime.

regards,
Lukas

---

## #24345 — Andi Gutmans — 2006-07-11T21:37:39+00:00

URL: https://externals.io/message/24328#24345 · In reply to: #24328

I definitely think that for production apps we should be able to turn this
off. It could significantly slow down apps. 

> -----Original Message-----
> From: Michael Wallner [mailto:mike@php.net] 
> Sent: Tuesday, July 11, 2006 3:35 AM
> To: internals@lists.php.net
> Subject: [PHP-DEV] More valuable error message handling
> 
> Hi,
> 
> I think many people agree that PHPs means for a developer to 
> get the last error message(s) are way suboptimal.
> 
> INI(track_errors) and $php_errormsg or hacking some error 
> handler magic are--despite sep. extension facilities--the 
> only one that come to mind, both cumbersome and unintuitive.
> 
> 
> I therefore propose some new functionality with possibly this 
> 3 new functions:
> 
> - `error_get_last()`
>  Get the last error message.
> 
> - error_get_all()
>  Get an array of all occurred errors.
> 
> - error_clear_all()
>  Reset error stack.
> 
> Return values and parameters are subject to discussion, as 
> well as when PHP puts errors into this stack, eventually if 
> track_errors is enabled?
> 
> 
> Thoughts, objections, flames?
> 
> 
> 
> PS: Sorry, if that comes through twice.
> 
> Regards,
> --
> Michael
> 
> --
>  To 
> unsubscribe, visit: http://www.php.net/unsub.php

---

## #24350 — Zeev Suraski — 2006-07-12T15:13:52+00:00

URL: https://externals.io/message/24328#24350 · In reply to: #24328

I think that `error_get_last()` makes sense, but not the other 
two.  You can fairly easily implement that using an error handler if 
you'd like, and as Andi said, keeping track of all of the errors that 
happened on a production server doesn't make sense from a performance 
(and possibly even memory) perspective(s).

Zeev

At 13:35 11/07/2006, Michael Wallner wrote:
>Hi,
>
>I think many people agree that PHPs means for a developer to
>get the last error message(s) are way suboptimal.
>
>INI(track_errors) and $php_errormsg or hacking some error
>handler magic are--despite sep. extension facilities--the
>only one that come to mind, both cumbersome and unintuitive.
>
>
>I therefore propose some new functionality with possibly
>this 3 new functions:
>
>- `error_get_last()`
>Get the last error message.
>
>- error_get_all()
>Get an array of all occurred errors.
>
>- error_clear_all()
>Reset error stack.
>
>Return values and parameters are subject to discussion, as well as
>when PHP puts errors into this stack, eventually if track_errors is
>enabled?
>
>
>Thoughts, objections, flames?
>
>
>
>PS: Sorry, if that comes through twice.
>
>Regards,
>--
>Michael

---

## #24423 — Michael Wallner — 2006-07-17T10:03:43+00:00

URL: https://externals.io/message/24328#24423 · In reply to: #24347

Lukas Smith wrote:

> thats why i said that i would like to atleast be able to get the last
> error without having to mess/check track_errors ini setting. i think
> this is an acceptable compromise to always store the last error, no?
> 
> this covers 100% of all use cases i ever had where i would mess with
> the track_errors setting at runtime.

Here's a less impacting patch for an `error_get_last()` function:
http://dev.iworks.at/PATCHES/error_get_last.diff.txt

Can we agree on that?

-- 
Michael

---

## #24438 — Marcus Boerger — 2006-07-17T21:28:00+00:00

URL: https://externals.io/message/24328#24438 · In reply to: #24423

Hello Michael,

  looks quite good now :-) If it were up to me i'd say commit.

best regards
marcus

Monday, July 17, 2006, 12:03:43 PM, you wrote:

> Lukas Smith wrote:

> > […]

> Here's a less impacting patch for an `error_get_last()` function:
> http://dev.iworks.at/PATCHES/error_get_last.diff.txt

> Can we agree on that?

> -- 
> Michael




Best regards,
 Marcus

---

## #24443 — Ilia Alshanetsky — 2006-07-17T21:33:49+00:00

URL: https://externals.io/message/24328#24443 · In reply to: #24423

Looks good to me, although I'd prefer you returned an associated  
array rather then an object.




> Lukas Smith wrote:
>
> > […]
>
> Here's a less impacting patch for an `error_get_last()` function:
> http://dev.iworks.at/PATCHES/error_get_last.diff.txt
>
> Can we agree on that?
>
> -- 
> Michael
>
> -- 
> 
> 
>
>

Ilia Alshanetsky

---

## #24441 — Zeev Suraski — 2006-07-17T21:56:23+00:00

URL: https://externals.io/message/24328#24441 · In reply to: #24443

Agreed - it looks good, but should return an array instead of an object.

Zeev

At 00:33 18/07/2006, Ilia Alshanetsky wrote:
>Looks good to me, although I'd prefer you returned an associated 
>array rather then an object.
>
>
>
>
> > […]
>
>Ilia Alshanetsky

---

## #24458 — Michael Wallner — 2006-07-18T10:38:39+00:00

URL: https://externals.io/message/24328#24458 · In reply to: #24443

Ilia Alshanetsky wrote:
> Looks good to me, although I'd prefer you returned an associated
> array rather then an object.

What for do we have object dereferencing then? As gimmick or buzzword?


$err = `error_get_last()`;
echo $err["message"];

vs.

echo `error_get_last()`->message;


One can still cast the stdClass instance to an array.

-- 
Michael

---

## #24459 — Antony Dovgal — 2006-07-18T10:42:14+00:00

URL: https://externals.io/message/24328#24459 · In reply to: #24458

> Ilia Alshanetsky wrote:
> > […]
> 
> What for do we have object dereferencing then? As gimmick or buzzword?

Definitely not for returning errors.
Array perfectly fits here. 
 
> $err = `error_get_last()`;
> echo $err["message"];
>
> vs.
> 
> echo `error_get_last()`->message;

And if there was no error before that - what would you get?

> One can still cast the stdClass instance to an array.

-- 
Wbr, 
Antony Dovgal

---

## #24467 — Ilia Alshanetsky — 2006-07-18T14:23:50+00:00

URL: https://externals.io/message/24328#24467 · In reply to: #24458

Just because we have objects it does not mean we need to use them all  
the time. In this instance IMO it makes absolutely no sense to use an  
object, it only creates extra overhead. If you want the patch to be  
included in 5.2, please change the function to return an associated  
array.




> Ilia Alshanetsky wrote:
> > […]
>
> What for do we have object dereferencing then? As gimmick or buzzword?
>
>
> $err = `error_get_last()`;
> echo $err["message"];
>
> vs.
>
> echo `error_get_last()`->message;
>
>
> One can still cast the stdClass instance to an array.
>
> -- 
> Michael
>
> -- 
> 
> 
>
>

Ilia Alshanetsky
