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";}}?> Quote Link to comment 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.