-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5magicMethods.php
More file actions
161 lines (150 loc) · 3.22 KB
/
Copy path5magicMethods.php
File metadata and controls
161 lines (150 loc) · 3.22 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
//class Person{
// public $name = 'Jane';
// private $phone = 12346;
//
// public function __construct()
// {
// echo "<br/>I am the constructor<br/>";
// }
//
// public function __destruct()
// {
// echo "<br/>I am the destructor<br/>";
// }
//
// public function __toString()
// {
// return "The name of the person is: ".$this->name;
// }
//
//
//}
//
//$p = new Person();
//echo $p;
//class Person1{
// public $name = 'Jane';
// private $phone = 12346;
//
// //cand se apealeaza o proprietate care nu exista
// public function __get($propName)
// {
// if ($propName==="username") {
// return $this->name;
// } else {
// return "Property \"$propName\" does not exists.";
// }
// }
//
// //cand se actualizeaza o proprietate care nu exista
// public function __set($name, $value)
// {
// if ($name==="username") {
// $this->name = $value;
// }
// }
//
// //when we try to execute an not existing method
// public function __call($name, $arguments){
// //var_dump($name, $arguments);
// if ($name==="getMobilePhone") {
// return $this->phone;
// }else if($name==="setMobilePhone"){
// call_user_func_array([$this, 'setPhone'], $arguments);
// }
// }
//
// //when we try to execute an not existing static method
// public static function __callStatic($name, $arguments)
// {
// echo "Call of \"$name\" static methodod was called";
// }
//
// public function getPhone(): int
// {
// return $this->phone;
// }
//
//
// public function setPhone(int $phone): Person1
// {
// $this->phone = $phone;
// return $this;
// }
//}
//
//$p = new Person1();
//$p->username='Marry';
//$p->setMobilePhone(1111111);
//echo $p->getMobilePhone();
//Person1::hello();
//echo p();
//class Person3{
// public $name = "Jane";
// private $phone = 123456;
//
//
//
// //use object as a function
//
// /**
// * Person3 constructor.
// * @param string $name
// * @param int $phone
// */
// public function __construct(string $name, int $phone)
// {
// $this->name = $name;
// $this->phone = $phone;
// }
//
// public function __invoke()
// {
// return "The object was used as a function";
// }
//
// //called before serialization
// public function __sleep()
// {
// unset($this->phone);
// return ['name'];
// }
// //called after serialization
// public function __wakeup()
// {
// echo "I am waking up";
// }
//
//}
//
//$p = new Person3("Anna", 123123);
//var_dump(is_callable($p));
//echo $p();
//
//$obSerialized = serialize($p);
//
//$newObject = unserialize($obSerialized);
//
//var_dump($obSerialized, $p, $newObject);
class Person4{
public $name;
private $phone;
/**
* Person4 constructor.
* @param $name
* @param $phone
*/
public function __construct($name, $phone)
{
$this->name = $name;
$this->phone = $phone;
}
public function __clone()
{
var_dump($this);
}
}
$p = new Person4("Johny",1212121212);
var_dump($p);
$newPerson = clone $p;