|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-01-26 23:36 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
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.