flyhoney Posted August 13, 2008 Share Posted August 13, 2008 In PHP 4, is it possible to include 2 classes of the same name, but different parent classes? For example: class Foo { } class Bar { } class Foo2 extends Foo { } class Foo2 extends Bar { } As expected PHP throws this error: Fatal error: Cannot redeclare class foo2 in blahblah on line 2 Is there a way around this? (I know it is a dumb question but my situation is complicated) Quote Link to comment https://forums.phpfreaks.com/topic/119418-including-classes-with-same-name-but-different-parent/ Share on other sites More sharing options...
trq Posted August 13, 2008 Share Posted August 13, 2008 While Foo2 can extend either Foo or Bar it cannot extend both. Also you are unable to redeclare a class within the same request. Quote Link to comment https://forums.phpfreaks.com/topic/119418-including-classes-with-same-name-but-different-parent/#findComment-615193 Share on other sites More sharing options...
Grayda Posted August 13, 2008 Share Posted August 13, 2008 Perhaps you could try: <?php class baseClass { // Core functions here } class extendedClass extends baseClass { // Extended functions here } class yourClass extends extendedClass { // And finally, your class that inherits stuff from two classes! } $myClass = new yourClass; ?> Is that what you're after? Quote Link to comment https://forums.phpfreaks.com/topic/119418-including-classes-with-same-name-but-different-parent/#findComment-616002 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.