Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-19-2009, 05:31 AM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
Question about default error behavior in PHP5.
I am an experienced C++ programmer but am new to PHP. I would like to develop for PHP5 but have some questions.
I need to know the default behavior of PHP5 functions when an error occurs. For example, in PHP4 (I believe) functions return FALSE or some other error code. In PHP5 it is my understanding that functions throw an Exception on error. So ... my question is ... do ALL PHP5 functions throw errors when an error occurs, or only certain ones, or how exactly does that work?
If only some PHP5 functions throw (and not all), where do you find documentation outlining this (which ones do and which ones don't).
I ask this because the only documentation I can find on PHP functions on the web are not version specific in any way. They say ... "returns FALSE" or some other error code but do not mention anywhere if they throw Exceptions. It would simplify things a LOT to know if ALL PHP5 functions that CAN error throw errors, or some other way to know PHP5s behavior on erring functions.
Thank you for your help.
03-19-2009, 05:54 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
- No. PHP5 is backwards compatible with PHP4 code, so any function existing prior to PHP5 will handle errors in the documented way. This does not necessarily mean they will return false, null, etc, they may just trigger a warning and continue processing.
- Finding documentation on exceptions is quite difficult. I'm trying to recall if any PHP5 only functions (or specifically the object methods) actually throw exceptions. You'll handle a lot of exceptions from custom written objects though.
Does that answer you're question? The PHP api will state any deviations for the return values, but I'm pretty certain that the only major changes occured between lower versions of PHP4, and nothing was altered for PHP5 in this regard.
Although PHP5.1+ has a great OO core to it now, there seems to be little OO usage in the core language itself. A few extensions make extensive use of it, common ones you'll see are MySQLi, ArrayObject (spl) and other datatypes, and DOMDocument.
Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');