Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question about default error behavior in PHP5.

    Hello,

    I am an experienced C++ programmer but am new to PHP. I would like to develop for PHP5 but have some questions.

    Question 1)
    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?

    Question 2)
    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.
    Jeremy

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    1. 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.
    2. 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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •