Jump to content

php code


Monica22

Recommended Posts

Hi I am new to this site and was hoping to get a little help. I am in the learning stages and creating an object-oriented programming using php.  I have two files, an idex file and a vehicle.php file. I keep getting the following errors: 

Parse error: syntax error, unexpected ';', expecting T_FUNCTION in/home/msj03/html/lis5367/lib/vehicle.php on line 92

 

The last line, the one in red is line 92- can anyone help? Thanks,

 

<?php
//define class
class vehicle1
{
 
//private properties (class variables)
private $vin;
private $manufacturer;
private $type;
private $color;
private $price;
 
//public methods/functions
//default constructor
public function __construct($vin="12345678901234567", $manufacturer="Toyota", $type="Tundra", $color="White", $price=25000)
{
$this->vin = $vin;
$this->manufacturer = $manufacturer;
$this->type = $type;
$this->color = $color;
$this->price = $price;
}
 
 
function __destruct()
{
//unset($this);
echo "Destroying " . $this->vin . "<br />";
}
 
//value-returning functions
//getter methods/functions (get object's properties)
public function getvehicle1()
{
return $this->vin . " " . $this->manufacturer . " " . $this->type . " " .  $this->color . " " . $this->price . " " ;
}
 
 
public function  getvin()
{
return $this->vin;
}
 
public function getmanufacturer()
{
return $this->manufacturer;
}
 
public function gettype()
{
return $this->type;
}
 
public function getcolor()
{
return $this->color;
}
 
public function getprice()
{
return $this->price;
}
 
 
//setter methods/functions (set object's properties)
public function setvin($vin)
{
$this->vin = $vin;
}
 
public function setmanufacturer($manufacturer)
{
$this->manufacturer = $manufacturer;
}
 
public function settype($type)
{
$this->type = $type;
}
 
public function setcolor($color)
{
$this->color = $color;
}
 
public function setprice($price)
{
$this->price = $price;
 
 
}//end class

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/283938-php-code/
Share on other sites

A little more help if possible... My page is not giving me line breaks- any idea why?

 

 

<?php
include('../lib/vehicle.php');
 
 
$vehicle1 = new vehicle(); 
$vehicle2 = new vehicle("122445566778899", "Ford", "Edge", "Black", 50000);
 
echo "<b>Returning Vehicle Properties:</b><br> />";
 
echo "<b> Vehicle 1:</b>";
 
echo "Vin:" . $vehicle1->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle1->gettype() . " ";
echo "Color:" . $vehicle1->getcolor() . " ";
echo "Price:" . $vehicle1->getprice() . " ";
 
 
 
 
echo "<b> Vehicle 2:</b> ";
echo "Vin:" . $vehicle2->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle2->gettype() . " ";
echo "Color:" . $vehicle2->getcolor() . " ";
echo "Price:" . $vehicle2->getprice() . " ";
 
 
 
 
echo "<b> Vehicle2 (After Changing Property Values):</b> ";
echo "Vin:" . $vehicle2->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle2->gettype() . " ";
echo "Color:" . $vehicle2->getcolor() . " ";
echo "Price:" . $vehicle2->getprice() . " ";
 
"<br />";
?>
Link to comment
https://forums.phpfreaks.com/topic/283938-php-code/#findComment-1458856
Share on other sites

 

<?php
include('../lib/vehicle.php');
 
 
$vehicle1 = new vehicle(); 
$vehicle2 = new vehicle("122445566778899", "Ford", "Edge", "Black", 50000);
 
echo "<b>Returning Vehicle Properties:</b><br />";
 
echo "<b> Vehicle 1:</b>";
 
echo "Vin:" . $vehicle1->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle1->gettype() . " ";
echo "Color:" . $vehicle1->getcolor() . " ";
echo "Price:" . $vehicle1->getprice() . " ";
 
echo "<br />";
 
 
echo "<b> Vehicle 2:</b> ";
echo "Vin:" . $vehicle2->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle2->gettype() . " ";
echo "Color:" . $vehicle2->getcolor() . " ";
echo "Price:" . $vehicle2->getprice() . " ";
 
"<br />";
 
 
echo "<b> Vehicle2 (After Changing Property Values):</b> ";
echo "Vin:" . $vehicle2->getvin() . " ";
echo "Manufacturer:" . $vehicle1->getmanufacturer() . " ";
echo "Type:" . $vehicle2->gettype() . " ";
echo "Color:" . $vehicle2->getcolor() . " ";
echo "Price:" . $vehicle2->getprice() . " ";
 
"<br />";
?>
 
I personally wouldn't mix it up all up like this but the above should work, you didn't have a line break between the two cars.
Link to comment
https://forums.phpfreaks.com/topic/283938-php-code/#findComment-1458869
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.