-1

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!

Tony Bogdanov
  • 7,436
  • 10
  • 49
  • 80

3 Answers3

3

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.

alex
  • 479,566
  • 201
  • 878
  • 984
  • He can do `if( !is_callable( 'foo')){function foo(){}}` – Vyktor Feb 04 '12 at 22:32
  • @Vyktor True, but that isn't suppressing any errors. It may work for the OP though. – alex Feb 04 '12 at 22:34
  • Yes I know but it may give him easy solution to his problem. What do you mean by OP? – Vyktor Feb 04 '12 at 22:41
  • @Vyktor Original Poster. I used his previous question for context too... he wants to redefine ionCube encoded functions and let their redefinitions fail silently. – alex Feb 04 '12 at 22:55
  • btw: there's http://php.net/manual/en/book.runkit.php this little thing – Vyktor Feb 04 '12 at 23:09
3

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

ghstcode
  • 2,902
  • 1
  • 20
  • 30
0

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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345