-
Notifications
You must be signed in to change notification settings - Fork 0
/
traits_static-version.php
107 lines (89 loc) · 2.02 KB
/
traits_static-version.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
*=============================================================
* <traits_static-version.php>
* object oriented programming: Traits in PHP
*
* @author Muhammad Anwar Hussain<[email protected]>
* Created on: 10th June 2019
* ============================================================
*/
trait FlightServices
{
abstract static public function seat();
abstract static public function food();
public static function serviceXYZ()
{
echo __METHOD__.'<br>';
}
}
trait FlightInfo
{
public static function airline($name)
{
echo 'Welcome to '. $name.'<br>';
}
public static function ticketFare($cost)
{
echo 'Ticket Price: '. $cost .'<br>';
}
public static function luggageWeight($weight)
{
echo 'Allowed Luggage Weight: '. $weight .'<br>';
}
}
class Economic
{
use FlightInfo;
use FlightServices;
public static function seat()
{
echo 'Seat: standard'.'<br>';
}
public static function food()
{
echo 'Food: good'.'<br>';
}
}
class Business
{
use FlightInfo;
use FlightServices;
public static function seat()
{
echo 'Seat: Luxurious'.'<br>';
}
public static function food()
{
echo 'Food: Excellent'.'<br>';
}
}
class FlightBooking
{
private static $airline;
private static $cost = [];
private static $weight = [];
public static function setFlight($name, $weight = [], $cost = [])
{
self::$airline = $name;
self::$weight = $weight;
self::$cost = $cost;
}
public static function confirmFlight($c)
{
$class = strtolower($c);
$c::airline(self::$airline) .'<br>';
echo 'Class: '. strtoupper($c) .'<br>';
$c::serviceXYZ();
$c::seat();
$c::food();
$c::luggageWeight(self::$weight[$class]);
echo '------------------------------------------------<br>';
$c::ticketFare(self::$cost[$class]);
}
}
FlightBooking::setFlight('Biman Bangladesh Airlines', ['economic' => '30 kg', 'business'=> '50 kg'], ['economic' => '$ 950', 'business'=> '$ 1500']);
FlightBooking::confirmFlight('Economic');
echo '<br>';
FlightBooking::confirmFlight('Business');
?>