Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Handling fatal syntax errors - PHP

  • 01-02-2007 2:58pm
    #1
    Closed Accounts Posts: 25,848 ✭✭✭✭


    Hi guys,

    I have a php web site nearly ready to go into production. It has fancy error handling for displaying an custom error message to the user if anything happens to go wrong, and as its a production system i'm turning off "display_errors" in the php.ini file.

    The only problem is that if there is a syntax error in the scripts themselves they won't run, and neither will all the fancy custom error messages. the user just gets a blank page.

    I've been searching Google for a solution to this but everything I read requires that the actual scripts themselves are free from syntax errors otherwise any error handling won't be compiled and run when the page is loaded (and you would get an error outputted if "display_errors" was turned on.)

    Is there anyway to set a custom error message to be displayed even if the php program cannot understand the PHP code itself (ie syntax error)


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Not sure.

    As best I know, out of the box PHP doesn't throw a 500 error when it encounters a fatal coding error. Instead it dies "gracefully", allowing the server to just output a blank page. It may be possible to tell PHP to throw a 500 error, I'm not sure.

    Throwing errors for syntax errors generally assumes that the page has never worked - the PHP engine will show an error for *any* fatal syntax problems in the code, and not just those it encounters as it executes the script.

    So you can pretty much assume that if the pages are working in testing, then you shouldn't encounter any syntax errors when you go live.

    Other syntactical "flaws" (such as forgetting to put a $ before a variable name) won't be fatal, and you should see your fancy errors.

    If you want to do development, then I would have an offline duplicate of the site exactly, except that error handling is on E_ALL. Make any changes in the development site, test them, then upload the files to the live site.


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    If it works in testing without syntactical errors, it will work on upload and you won't get syntactical errors. Even if the versions of PHP on the server and your test machine are different (which I'd advise you check that they're not!) then you'll still get fancy errors instead of base syntactical errors.


Advertisement