I have two classes as below:
product.php
index.phpPHP Code:<?php
class Product {
private $id;
private $name;
private $price;
private $lastUpdate;
private $category;
//public function Product($id) {
// $this->id = $id;
//}
public function Product($id, $name, $price, $lastUpdate) {
$this->id = $id;
$this->name = $name;
$this->price = $price;
$this->lastUpdate = $lastUpdate;
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getPrice() {
return $this->price;
}
public function setPrice($price) {
$this->price = $price;
}
public function getLastUpdate() {
return $this->lastUpdate;
}
public function setLastUpdate($lastUpdate) {
$this->lastUpdate = $lastUpdate;
}
public function getCategory() {
return $this->category;
}
public function setCategory($category) {
$this->category = $category;
}
}
?>
When I put "public" for class Product, error occur and if I remove it, no error:PHP Code:<?php
include('product.php');
include('ShoppingCartItem.php');
//include('ShoppingCart.php');
$product = new Product(1, 'Note book', 25000, '25/1/2013');
//echo $product->getId();
$scItem = new ShoppingCartItem($product);
//echo $scItem->getQuantity();
?>
PHP Code:<?php
public class Product {
//
}
?>Why don't I do this? And why don't I add a construct function "Product" with one parameter "$id"?Parse error: syntax error, unexpected T_PUBLIC in C:\xampp\htdocs\demo\passing_object_to_function\product.php on line 2



Reply With Quote



Bookmarks