jd2007 Posted August 8, 2007 Share Posted August 8, 2007 i'm sorry i posted this here, there is no one in oop help forums and i need help urgently... i get this error : Catchable fatal error: Object of class Aeroplane could not be converted to string in C:\AppServ\www\AirFighter.php on line 8 this is the php code: <?php include("aeroplane.php"); $AirFigther=new Aeroplane("2031", "F-16", "US Air Force Fighter"); echo $AirFighter; echo "<br /><br />"; $UnitedAirlines=new Aeroplane("1220", "Boeing 777", "United Airlines Passenger Aircraft"); echo $UnitedAirlines; ?> the class aeroplane: <?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; } } ?> Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/ Share on other sites More sharing options...
ToonMariner Posted August 8, 2007 Share Posted August 8, 2007 echo $AirFighter; $AirFighter is an object not a string - you can convert in php5 using the __tostring method http://uk.php.net/manual/en/language.oop5.magic.php otherwise you should be echoing out properties of the object like so... echo $Airfighter->indentity; you will get the same error on line 11 once you have this one sorted.... Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318279 Share on other sites More sharing options...
pranav_kavi Posted August 8, 2007 Share Posted August 8, 2007 hello.. i ran ur piece of code...i did get the output as No: 2031 Type: F-16 Usage: US Air Force Fighter No: 1220 Type: Boeing 777 Usage: United Airlines Passenger Aircraft Catchable fatal error: Object of class Aeroplane could not be converted to string in C:\xampp\htdocs\xampp\temp.php on line 13 The problem was in echoing the objects of class Aeroplane.You dont need to do tat since the values are being echoed in the constructor. Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318281 Share on other sites More sharing options...
ToonMariner Posted August 8, 2007 Share Posted August 8, 2007 I know - I was giving you an example of how to echo out properties of an object... what did you want to echo out? Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318286 Share on other sites More sharing options...
jd2007 Posted August 8, 2007 Author Share Posted August 8, 2007 thanks..its ok now....how can i ovveride vaiables.... Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318289 Share on other sites More sharing options...
jd2007 Posted August 8, 2007 Author Share Posted August 8, 2007 i wanted to echo the properties which is no., type, usage Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318290 Share on other sites More sharing options...
pranav_kavi Posted August 8, 2007 Share Posted August 8, 2007 I am not sure whether i have got u right rgarding 'overriding variables'. s tis wat u want?? include("aeroplane.php"); $AirFigther=new Aeroplane("2031", "F-16", "US Air Force Fighter"); echo "<br /><br />"; $UnitedAirlines=new Aeroplane("1220", "Boeing 777", "United Airlines Passenger Aircraft"); echo "<br /><br />"; $aa=new Aeroplane("1221","aa"); echo "<br /><br />"; $bb=new Aeroplane("1221"); aeroplane.php : class Aeroplane { function Aeroplane($no="0", $type="", $usage="") { $identity="<b>No:</b> ".$no."<br /><b>Type:</b> ".$type."<br /><b>Usage:</b> ".$usage; echo $identity; } } Link to comment https://forums.phpfreaks.com/topic/63860-why-do-i-get-this-error-below-class-problem/#findComment-318300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.