Frage

I wonder if it is possible to supress errors in PHP like when redeclaring functions, so the execution wont break and the script would just use the first time declared function?

Thanks in advance!

War es hilfreich?

Lösung

I wonder if it is possible to supress errors in PHP...

PHP has many options to supress errors, such as the error_reporting() function and display_errors option in php.ini.

...so the execution wont break and the script would just use the first time declared function?

Re-declaring functions is a fatal error in PHP, which you generally can not gracefully recover from.

You could preprocess the source code, removing duplicate function declarations.

Andere Tipps

It's probably not the best idea to suppress errors, but there is certain logic you can use in your code to circumvent them.

Check to see if a function has previously been declared:

if(!function_exists("my_function"))
{
   function my_function() 
   {
     // ... do stuff
   }
}

Reference: http://php.net/manual/en/function.function-exists.php

Suppressing error messages is generally bad idea.
It is considered good practice to repair the error instead. Hint: it is not as hard as it seems.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top