/
Product.php
44 lines (37 loc) · 963 Bytes
/
Product.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Created by PhpStorm.
* User: John Kagga
* Date: 8/1/2015
* Time: 9:46 AM
*/
class Product {
public $name = 'default_name';
public $price = 0;
public $desc = "default_description";
//static property
public static $manufacturer = 'default_maker';
//constructor
function __construct($name, $price, $desc)
{
$this->name = $name;
$this->price = $price;
$this->desc = $desc;
}
//method
public function getInfo (){
return "Product name: ".$this->name;
}
public function maker(){
//$this and -> cannot be used on static methods
return self::$manufacturer;
}
}
$product = new Product("shirt",20,"short-selves");
echo $product->getInfo();
echo '<br><br><br>';
//using the method to get the maker
echo $product->maker();
//or use :: to access the method, property
echo '<br><br><br>';
echo $product::$manufacturer;