Skip to content

Commit fae3dde

Browse files
committed
class object complete
1 parent bc861ae commit fae3dde

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

1. Classes-Objects/index.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
<?php
22

3+
class Car
4+
{
5+
public $name;
6+
public $color;
7+
8+
function setName($name)
9+
{
10+
$this->name = $name;
11+
}
12+
function getName()
13+
{
14+
return $this->name;
15+
}
16+
17+
function getColor()
18+
{
19+
return $this->color;
20+
}
21+
function setColor($color)
22+
{
23+
$this->color = $color;
24+
}
25+
}
26+
27+
$car1 = new Car();
28+
$car2 = new Car();
29+
// var_dump($car1 instanceof Car);
30+
$car1->setName("volvo");
31+
$car1->setColor("black");
32+
$car2->name = "audi";
33+
$car2->color = "blue";
34+
35+
echo "Car-1: Name: " . $car1->getName() . " Color: " . $car1->getColor() . "</br>";
36+
echo "Car-2: Name: " . $car2->getName() . " Color: " . $car2->getColor() . "</br>";
37+
338
?>
439
<!DOCTYPE html>
540
<html lang="en">

0 commit comments

Comments
 (0)