Drop Shadow

PHP cannot redeclare function

In PHP 4, you could declare the same function multiple times. In PHP 5, you cannot. Normally, you don’t declare functions multiple times—but you are if you include the same file more than once, and that file has functions in it. The second time you include the file, you’ll get an error like:

Cannot redeclare doForm() (previously declared in /httpd/includes/email.php:22) in /httpd/includes/email.php on line 56

Solution:

  1. If you don’t need to include it twice, then remove the extra include.
  2. If you need to have it in two places, and sometimes those two places will both be hit, use “include_once”. This will not run any code the second time around, though, so if you need code to run outside of functions, this won’t work for you.
  3. If the include file runs code outside of functions, that you need to run each time you include it, then separate the functions into a separate file. In the include file, use “include_once” to load the function file.