Thanks Louis, Worked a treat!
-----Original Message----- From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com] Sent: 14 March 2011 15:10 To: Crowley, Brendan - Dell Team Subject: Re: [PHP] PHP Fatal error: Cannot redeclare class what about http://ch2.php.net/namespaces in php 5.3? 2011/3/14 <brendan_crow...@dellteam.com>: > 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 { } ?> > > > > > >