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
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
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.
Edited by AaronClifford
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.