-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_5.php
More file actions
31 lines (25 loc) · 698 Bytes
/
2_5.php
File metadata and controls
31 lines (25 loc) · 698 Bytes
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
<?php
class User {
private $name;
private $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
// __get() MAGIC METHOD
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
}
$user1 = new User('Gauresh', 22);
// $user1->setName('Pritesh');
// echo $user1->getName();
echo $user1->__get('age');