zipp Posted October 12, 2009 Share Posted October 12, 2009 I have 6 files, and two of them do not seem to want to play well. I keep getting a "Cannot redeclare class" error. ** edit ** I know its these 2 files, because when i comment out the include for login.php, the error goes away. **end edit** The full error: Fatal error: Cannot redeclare class Base in \core\Base.php on line 7 Base.php <?php /** * Base.php is the base class for all functions. * */ class Base { function __construct() { include("Admin.php"); include("Feed.php"); include("Login.php"); include("Session.php"); include("SQLManager.php"); include("Twitter.php"); } function __destruct() { } } ?> Login.php <?php /** * Login.php is the class for all Application login functions. * */ class Login extends Base { function __construct() { } function Login() { } function Logout() { } function __destruct() { } } ?> All of the files that are included in the Base __construct, extend Base. Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/177479-solved-php-cannot-redeclare-class/ Share on other sites More sharing options...
KevinM1 Posted October 12, 2009 Share Posted October 12, 2009 If that's all you're using Base for, why even bother? Simply create your own __autoload() function to automatically include()/require() the correct class files when needed. Quote Link to comment https://forums.phpfreaks.com/topic/177479-solved-php-cannot-redeclare-class/#findComment-935789 Share on other sites More sharing options...
zipp Posted October 13, 2009 Author Share Posted October 13, 2009 That's not all base will be used for. I am only 0.5% done with this project, and I ran into a snag like that. However, I figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/177479-solved-php-cannot-redeclare-class/#findComment-935851 Share on other sites More sharing options...
trq Posted October 13, 2009 Share Posted October 13, 2009 Still, the idea of every class extending a 'Base' like that is ridiculous. How can the classes (assuming these are the names of the classes included) Session, SQLManager and Twitter share the same parent? There names don't suggest that they would be related at all. Quote Link to comment https://forums.phpfreaks.com/topic/177479-solved-php-cannot-redeclare-class/#findComment-935853 Share on other sites More sharing options...
zipp Posted October 13, 2009 Author Share Posted October 13, 2009 I completely agree. That was just a bad comment Quote Link to comment https://forums.phpfreaks.com/topic/177479-solved-php-cannot-redeclare-class/#findComment-935888 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.