-4

Is it possible, and how to bypass the fatal error and still load the rest of the php page, I have a script the logs all errors on sql database, and I want that my php index, that is mostly html, still loads, and hide the fatal error.

this is the code that throws a fatal error:

try {
$queryConfiguracao = sqlQuery("SELECT * FROM definicoes");
$online = mysql_result($queryConfiguracao, 0);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

And the error that is that i removed the function in cause:

Fatal error: Call to undefined function sqlQuery()

but this still doesn't load the page

Hugo Alves
  • 79
  • 7
  • 2
    It is possible. Here's how: Step 1: Fix the fatal error. – Niet the Dark Absol Sep 13 '13 at 19:51
  • What you really need to do is _code around the error_. If you have code that generates fatal errors which are not parse errors, it is assuredly possible to code it such that the errors are not triggered/ – Michael Berkowski Sep 13 '13 at 19:51
  • 2
    **bang** your legs have just been blown off in an explosion. Get up and run a marathon... c'mon... what's the hold up? – Marc B Sep 13 '13 at 19:52
  • By definition "fatal errors" cannot be recovered from. That's why they're fatal. – Lumberjack Sep 13 '13 at 19:53
  • 1
    possible duplicate of [How do I catch a PHP Fatal Error](http://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-error) – Michael Berkowski Sep 13 '13 at 19:59
  • Well, if your fatal error is that you are calling a function that is not defined, then it is best to fix the code and DEFINE THAT FUNCTION, probably by including the file that has the definition already. It is NOT a good idea to ignore that error. – Sven Sep 13 '13 at 20:13
  • It depends, can you recover from a fatal injury? – Sammitch Sep 13 '13 at 20:16

1 Answers1

0

You can use function_exists() to determine if the function exists and bypass that part of the code if the function does not exist. This seems quite sloppy to me though.

Documentation: http://php.net/function.function-exists.php

if (function_exists("sqlQuery")) {
    $queryConfiguracao = sqlQuery("SELECT * FROM definicoes");
    $online = mysql_result($queryConfiguracao, 0);
} else {
    $online = array();
}

Or something like that.

Jasper
  • 75,717
  • 14
  • 151
  • 146