-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy path11-const.php
46 lines (38 loc) · 1.33 KB
/
11-const.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
45
46
<?php
//======================================================================
// ASSEMBLER SCHOOL - PHP Object Oriented Programming
//======================================================================
/* File 11 - Constants */
// constants are unchangeable, we can use the word const to create them. The default visibility of class constants is public.
const APPNAME = 'ASSEMBLER APP';
class Internet
{
const SERVER = '122.23.4.5';
public static function connectInternet()
{
// We can refer to constants inside our class with self and double colon
return "connecting to " . self::SERVER . "...";
}
}
class Mobile
{
public $name;
protected $chipset;
protected $internalMemory;
private $imei;
public function __construct($name, $chipset, $internalMemory, $imei)
{
$this->name = $name;
$this->chipset = $chipset;
$this->internalMemory = $internalMemory;
$this->imei = $imei;
echo "+ CREATED " . $this->name . " WITH " . $this->internalMemory . " INTERNAL MEMORY +<br>";
}
// We can access constants with just name
public function runMobileApp()
{
return $this->name . " RUNS " . APPNAME . " : " . Internet::connectInternet();
}
}
$samsung = new Mobile('Samsung s20', 'Exynos', 128, '000111222333');
echo $samsung->runMobileApp();