Req #60897 [Com]: Advocating trigger_error instead of exit/die()
| From: | notdefix at hotmail dot com | Date: | Mon, 16 Jul 2012 15:41:55 +0000 |
| Subject: | Req #60897 [Com]: Advocating trigger_error instead of exit/die() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8556@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60897&edit=1
ID: 60897
Comment by: notdefix at hotmail dot com
Reported by: luiheidsgoeroe at hotmail dot com
Summary: Advocating trigger_error instead of exit/die()
Status: Open
Type: Feature/Change Request
Package: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The use of trigger_error('Error string', E_USER_ERROR); is far better than die();/exit();
However, in many cases, 'throw new Exception()' might be a better solution. I think it is
definately worth improving the examples, be it with exceptions or triggered errors, both are better
practice than die/exit.
Previous Comments:
------------------------------------------------------------------------
[2012-01-26 23:36:40] luiheidsgoeroe at hotmail dot com
Description:
------------
Although examples in the documentation are of course only meant as illustrations, we all know that
starting developers copy/paste huge chunks of code and then fiddle with the details to get things
working. Usually, this turns out alright, but the use of exit(<error message>) and/or
die(<error message>) on any error (mysql_connect comes to mind) is widespread in the
documentation. This is terrible to debug later, does not leave a message in the error log, and in
3rd party included libraries it is just plain evil.
I'd like to advocate:
1) Adding a note to exit()/die() that trigger_error('some message', E_USER_ERROR) would be
preferable in production (easily done if people agree with this).
2) Modifying most if not all examples in the documentation that use die() to that trigger_error() (a
lot of work).
It is of course debatable whether this should happen, as trigger_error() with display_errors on
differs with die() in also showing path & linenumber, which is not information visitors should
normally get, but then again, neither should display_errors be on. Also an issue could be it
clutters the examples somewhat with non-relevant statements, but it is not terribly more verbose
then the die()'s that are there now.
In my opinion, it would advocate good practices in coding and relieve a lot of irritation and
obscurity in debugging code from new coders and monitoring issues.
Should this be accepted as indeed the way to go, I would be perfectly willing to comb through the
documentation to alter die()/exit() statements to this format and submit a patch, but - as it will
take a while - not until there is a definite decision that this is what desirable, otherwise
I'd be wasting my time.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60897&edit=1