jd2007 Posted August 8, 2007 Share Posted August 8, 2007 <?php class Aeroplane { function Aeroplane($no, $type, $usage) { $identity="<b>No:</b> ".$no."<br /><b>Type:</b> ".$type."<br /><b>Usage:</b> ".$usage; echo $identity; } } class Cargo extends Aeroplane { function Cargo($no, $type, $usage, $goods); { $identity2="<b>No:</b> ".$no."<br /><b>Type:</b> ".$type."<br /><b>Usage:</b> ".$usage."<br /><b>Usage:</b> ".$goods; echo $identity2; } } ?> i want Cargo function to display all properties of Aeroplane (no, type, usage) and a additional property called goods. Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/ Share on other sites More sharing options...
NArc0t1c Posted August 8, 2007 Share Posted August 8, 2007 what's the error you are getting? We're not here to do you're work. Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/#findComment-318302 Share on other sites More sharing options...
jd2007 Posted August 8, 2007 Author Share Posted August 8, 2007 Fatal error: Non-abstract method Cargo::Cargo() must contain body in C:\AppServ\www\aeroplane.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/#findComment-318306 Share on other sites More sharing options...
pranav_kavi Posted August 8, 2007 Share Posted August 8, 2007 I think the error is bcos the base class(aeroplane) constructor is not invoked when the sub class constructor is calld. Read it somwhere: PHP 4 doesn't call constructors of the base class automatically from a constructor of a derived class. It is your responsibility to propagate the call to constructors upstream where appropriate. Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/#findComment-318313 Share on other sites More sharing options...
navjak Posted August 8, 2007 Share Posted August 8, 2007 Change the Class name or the function name of Cargo. Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/#findComment-318322 Share on other sites More sharing options...
pranav_kavi Posted August 8, 2007 Share Posted August 8, 2007 I wud like to know what PHP editor ur using...the error s comin up bcos u ve placed a ';' at the end of Cargo constructor. function Cargo($no, $type, $usage, $goods); Quote Link to comment https://forums.phpfreaks.com/topic/63861-how-to-extend-a-class/#findComment-318327 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.