-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.php
More file actions
34 lines (30 loc) · 830 Bytes
/
objects.php
File metadata and controls
34 lines (30 loc) · 830 Bytes
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
<?php
class Car
{
var $type, $color, $desc;
static $descGlobal = "It's a car";
private static function printDesc()
{
echo "Global desc: " . self::$descGlobal, PHP_EOL;
}
function __construct($type = "Trabant", $color = "White", $desc = "Classic")
{
$this->type = $type;
$this->color = $color;
$this->desc = $desc;
}
function printCar()
{
echo "Type: " . $this->type, PHP_EOL;
echo "Color: " . $this->color, PHP_EOL;
echo "Desc: " . $this->desc, PHP_EOL;
self::printDesc();
}
}
$car = new Car;
$car->type = "Ferrari";
$car->color = "Red";
$car->printCar();
$car2 = new Car("Audi", "Blue", "Very modern");
$car2->printCar();
// Car::printDesc(); // print desc globally - it produces error, because the method is private