开发者

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

I am getting this error for re-declaring saveorder() ho开发者_运维知识库wever, 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. }


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).


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.


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.


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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜