0

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

4
  • 5
    That code alone will not generate that error. You've over-simplified. Commented Dec 13, 2010 at 19:01
  • Also, did you investigate "line X"? And why would you call a function sayBlah? Commented Dec 13, 2010 at 19:03
  • Isn’t the error message self-explanatory? You redeclared that function that was previously declared at the mentioned position. Commented Dec 13, 2010 at 19:07
  • @aksu, please do not add php-functions to any more questions. It's a dictionary definition meta tag, in that it ties together entirely unrelated questions that are otherwise perfectly fine under the existing tags, in that it can not stand alone as a tag on questions, and in that it's unlikely to be a tag anyone would consider watching. Commented Feb 9, 2014 at 18:38

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This was totally it! Thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.