1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development PHP: Getting the last error

Discussion in 'Software' started by DougEdey, 21 Nov 2006.

  1. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    Is there anyway to detect when an error has occured in PHP and output it, currently the server settings are not to display any errors.
     
  2. FuzzyOne

    FuzzyOne

    Joined:
    19 Sep 2002
    Posts:
    1,839
    Likes Received:
    37
  3. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    http://uk.php.net/manual/en/ref.errorfunc.php

    Some useful stuff in the manual, on error handling.

    If you just want to display errors and the php.ini has them truned off, then put this at the start of the file in question:
    PHP:
    <?php
    error_reporting
    (E_ALL);
    ?>
     
    Last edited: 21 Nov 2006
  4. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    Actually, that won't work.

    If display_errors is set to off in php.ini, errors are off and that's it. error_reporting() only sets the level of error reporting, it doesn't explictly turn it on or off (ok... setting to E_NONE or whatever will effectively turn it off).

    Doug, the best way to do what you want is to (if Apache is checking for .htaccess files (via the AllowOverride directive)) give php a hint like so:

    <Files /path/to/my/php/file.php>
    php_flag display_errors on
    </Files>

    which will over-ride your php.ini setting. If you want to apply that to more than one php file, repeat the Files directive for the files you wish to display errors and notices in. And you can apply that to the entire directory by omitting the Files directive(s).

    If you can't use .htaccess you're SOL unless you can change the php.ini setting. Try Fuzzy's method, but again, I'd guess that if display_errors is off then even hooking php's error reporting function may be fruitless for ya. It is worth checking that avenue out though :)

    HTH :)
     
  5. Firehed

    Firehed Why not? I own a domain to match.

    Joined:
    15 Feb 2004
    Posts:
    12,574
    Likes Received:
    16
    It's worth noting that some hosts let you have a custom php.ini file for a given directory. I'm not quite sure how it works, but if your host supports it, just place a php.ini file containing the "display_errors on" line (or whatever it exactly is) and you should be OK.

    I've tried setting reporting to E_ALL and got nothing locally, as I had no idea that reporting was apparently off.

    So basically you should check in with your host and see if they'll allow custom php.ini settings, and how you would go about doing it. They may or may not, but I'd say RTT's method is better if it's an option.
     
  6. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    That is actually a damn good point. On a related note, MySQL checks a number of locations, including user home directories for my.cnf files :thumb:

    I suspect though based on Doug's previous posts that this might be work related rather than commercial web hosting type stuff (and what host would disable errors?*)

    *probably a good host** :D

    ** do they exist?
     
  7. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    considering its the Alpha dev server at work (beta for primary testing, delta secondary before actual release) I'm suprised that they haven't got warnings set.

    I eventually played around with the code to make the functions run from command prompt and found the errors out that way.

    Incidentally, the CLI method also doesn't have the File handling problems from my other post.
     
  8. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    ini_set(), if your allowed.
     
  9. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    which also doesn't work in this case ;) Fatal errors will be produced (and not shown, due to display_errors being off) before php has a chance to apply ini_set() :)
     
  10. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    Ok, should of read the manual first :blush:
     
  11. weknowtheworld

    weknowtheworld Banned

    Joined:
    8 Dec 2006
    Posts:
    28
    Likes Received:
    0
    Actually I think you have to edit the php.ini file..
     
  12. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    As said, this is solved (almost a month ago)
     

Share This Page