Req #60897 [Opn->Csd]: Advocating trigger_error instead of exit/die()
| From: | krakjoe@php.net | Date: | Sun, 06 Oct 2013 07:42:15 +0000 |
| Subject: | Req #60897 [Opn->Csd]: Advocating trigger_error instead of exit/die() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10436@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
Updated by: krakjoe@php.net
Reported by: luiheidsgoeroe at hotmail dot com
Summary: Advocating trigger_error instead of exit/die()
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: krakjoe
Block user comment: N
Private report: N
New Comment:
As you have correctly observed, documentation is not a work of best use code, they are illustrative
examples.
That's really the end of it; it is impractical to expect every example in the manual to be the
best possible version of the code that it is; not least of all, there are differing opinions on as
to what would constitute the best possible version.
Thanks for your input, but closing the bug, there really isn't a need to change.
Previous Comments:
------------------------------------------------------------------------
[2012-07-16 15:41:55] notdefix at hotmail dot com
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.
------------------------------------------------------------------------
[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