I have a function A in file B.inc
line 2: function A() {
...
line 10: }
In the apache log:
PHP Fatal error: Cannot redeclare A() (previously declared in B.inc:2) in B on line 10
I suppose you're using require "B.inc"
in multiple parts? Can you try using require_once
in all those instances instead?
Seems like your B.inc is parsed twice.
I had a similar problem where a function entirely contained within a public function within a class was being reported as redeclared. I reduced the problem to
class B {
function __construct() {
function A() {
}
}
}
$b1 = new B();
$b2 = new B();
The Fatal error: Cannot redeclare A() is produced when attempting to create $b2.
The original author of the code had protected the class declaration from being redeclared with if ( !class_exists( 'B' ) ) but this does not protect the internal function A() from being redeclared if we attempt to create more than one instance of the class.
Note: This is probably not the same problem as above BUT it's very similar to some of the answers in PHP Fatal error: Cannot redeclare class
Did you already declare A() somewhere else?
Or, are you calling B.inc twice on accident?
try using: require_once("B.inc");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With