forked from assembler-institute/oop-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-setters.php
42 lines (34 loc) · 1.04 KB
/
05-setters.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
<?php
//======================================================================
// ASSEMBLER SCHOOL - PHP Object Oriented Programming
//======================================================================
/* File 05 - Setters */
// Setters are methods for modifying properties values
class Mobile
{
public $name;
public $chipset;
public $internalMemory;
public function getInternalMemory()
{
return $this->internalMemory;
}
// setters are methods for changing properties
public function setInternalMemory($internalMemory)
{
echo "* CHANGED internal memory from " . $this->internalMemory;
$this->internalMemory = $internalMemory;
echo " to " . $this->internalMemory;
}
}
echo "<br>";
$modernMobile = new Mobile();
$modernMobile->name = "Samsung s20";
$modernMobile->chipset = "Exynos";
$modernMobile->internalMemory = 128;
echo "<br>";
echo $modernMobile->getInternalMemory();
echo "<br>";
$modernMobile->setInternalMemory(256);
echo "<br>";
echo $modernMobile->getInternalMemory();