PHP Fatal error: Cannot redeclare class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, I get the following error in my apache error log:
[14-Mar-2011 14:17:27] PHP Fatal error:  Cannot redeclare class
I created a simplified set of php files and classes to formulate this question.
I have 5 php files; 2 of which declare a class that has the same name in both. I know it would be very easy to change one of the class names, but I'm restricted because I'm working with legacy working code and an interface definition that cannot change either, here are the php files, how can I resolve this?, any help appreciated.
Thanks,
Brendan.

## phpFileOne.php ##
<?php
include_once './phpFileTwo.php';
include_once './phpFileFour.php';

$zIns = new Z();
$result = a($zIns);

// class Z is defined in phpFileFour.php
function a(Z $dataX) {
      $dataZ;
      $dataY = b($dataZ); // b is defined in phpFileTwo.php
      return $dataY;
}

echo '<p>result: '.$result.'</p>';
?>

## phpFileTwo.php ##
<?php
include_once './phpFileThree.php';
function b($dataW) {
      $dataU;
      $dataV = new A($dataU); // class A is defined in phpFileThree.php
      return $dataV->c();
}
?>

## phpFileThree.php ##
<?php
include_once './phpFileFive.php';
// class Z is defined in phpFileFive.php
class A extends Z {
      function __construct($dataM) {

      }

      function c() {
            return 'cValue';
      }
}
?>

## phpFileFour.php ##
<?php
// class Z defined in interface definition - cannot change name
class Z {
}
?>

## phpFileFive.php ##
<?php
// this class and class Z in phpFileFour.php have the same name!
// Legacy class Z - cannot change name
class Z {
}
?>






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux