redconservatory
redconservatory

Reputation: 21924

Php functions, syntax error?

I am trying to run a simple function, something to the effect of (pseudo-code)

function sayBlah()
{
  return "blah";
}

$sayit = sayBlah();

echo $sayit;

But I keeps getting the following error message:

Fatal error: Cannot redeclare sayBlah() previously declared on line X

Upvotes: 0

Views: 139

Answers (1)

marcusklaas
marcusklaas

Reputation: 492

This is probably caused when you include a file twice. Sometimes this is not trivial, because the line numbers in the error message correspond to the file in which it is included.

I.e. we have three files. File A. File B, includes file A. File C, includes file A and file B.

Then if you declare a function in file A, it will be declared twice because you are including file A twice. Once directly, and one more time indirectly.

You can solve this by replacing your require/ include calls by require_once or include_once calls respectively.

Upvotes: 3

Related Questions