pendelton Posted October 28, 2006 Share Posted October 28, 2006 This problem has been driving me mad for the past 13 hours. I have php 4 on an existing server and php 5.1.2 on a new server (which I am trying to migrate to). The below test code works fine on php 4, but fails with "Fatal error: Cannot redeclare class..." with php 5. The error only occurs for classes that use extends. Is there a bug in php 5? Has it been fixed in a later version (not that my SUSE server will let me install a later version despite trying for hours). Can someone please help or at least test this out for my on other versions of PHP?You will need 3 simple files to reproduce this problem. I know that the double include in test.php doesn’t make immediate sense but it simulates multiple includes from different file in a php project that contains over 2,000 files (remember, this all works fine on php 4). If you take out the "extends CTest3" from test2.inc and it works fine on PHP5.File 1: test.php<?require "test2.inc";require "test2.inc";?>File 2: test2.inc<?if (defined("CTEST2")) return;define("CTEST2", 1);require "test3.inc";class CTest2 extends CTest3{function CTest2(){ print "Test2";}}?>File 3: “test3.inc”<?if (defined("CTEST3")) return;define("CTEST3", 1);class CTest3{function CTest3(){ print "Test3";}}?> Link to comment https://forums.phpfreaks.com/topic/25440-cannot-redeclare-class-which-uses-extends/ Share on other sites More sharing options...
toplay Posted October 29, 2006 Share Posted October 29, 2006 Instead of using the define() and return, just use require_once (or include_once). Link to comment https://forums.phpfreaks.com/topic/25440-cannot-redeclare-class-which-uses-extends/#findComment-116144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.