RE: PHP Fatal error: Cannot redeclare class

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

 



Thanks Louis,

Worked a treat!

-----Original Message-----
From: Louis Huppenbauer [mailto:louis.huppenbauer@xxxxxxxxx] 
Sent: 14 March 2011 15:10
To: Crowley, Brendan - Dell Team
Subject: Re:  PHP Fatal error: Cannot redeclare class

what about http://ch2.php.net/namespaces in php 5.3?

2011/3/14  <Brendan_Crowley@xxxxxxxxxxxx>:
> 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