tags:

views:

47

answers:

5

Hi, I am getting this error for re-declaring saveorder() however, I don't think I am?!?

Cannot redeclare saveorder() (previously declared in :10) on line 71

8.function saveOrder()
9.{
10. include 'tables.php';
11. $orderId       = 0;
12. $shippingCost  = 5;

...

68. }
69. echo $orderId;
70. return $orderId;
71. }
+1  A: 

Either tables.php contains a function also called saveOrder(), or the file you posted actually IS tables.php. PHP can't have 2 functions with the same name in the same namespace.

Coronatus
When I comment out line 10. it simply moves the error onto line 11?
Tom
A: 

You could be including the file that contains the function more than once:

  include 'file.php';
  include 'file2.php';

file.php:

  include 'file2.php';

Cannot redeclare saveorder() (previously declared in :10) on line 71

Either use include_once or require_once to make sure it doesn't happen (this can cause problems if you try to include it twice in two separate locations (like first in a file, then later inside a function for some reason, the second one will not work if you include the _once part).

SeanJA
A: 

You must be including the current file (where the lines are from) multiple times.

An easy fix is using

if (!function_exists('saveOrder')) {
  function saveOrder() {...}
}

However, I recommend creating a new functions.php file, including in only once, and placing all functions there.

Joel L
A: 

this could also be caused be saveorder() being delcared inside another function that is called multiple times.

eg.

function func1()
{
   function saveorder()
   {
       echo 'x';
   }
   saveorder();
}

for ($i=0;$i<2;++$i)
    func1();
steelbytes
A: 

I get this too on Windows - I think this must be a bug in PHP since where you have ":10" I get all sort of strange symbols that do not occur anywhere in my code - ie. one time it might be ":0", next time ":196870" and the next time "!qhsu89s3". I also find that if I wait around a bit before refreshing then it normally sorts itself out.

Not too encouraging I have to say, but I presume a problem with PHP on Windows.

Jeremy