-
Notifications
You must be signed in to change notification settings - Fork 2
/
accessModifier.php
64 lines (55 loc) · 1.42 KB
/
accessModifier.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
<?php
class ForceUser{
public function userName(){
return $name = "Rafikul Islam Rafi";
}
private function userEmail(){
return $email = "rafikulswe@gmail.com";
}
protected function userMobile(){
return $mobile = "01729346959";
}
//public, private, protected all can be access from this class.
public function userDetails(){
$data = array(
'name' => $this->userName(),
'email' => $this->userEmail(),
'mobile' => $this->userMobile()
);
return $data;
}
}
$forceUser = new ForceUser;
class RecentUser extends ForceUser{
//public function can be access from child class.
public function showUserName(){
return $this->userName();
}
//protected function can be access from child class.
public function showUserMobile(){
return $this->userMobile();
}
//private function can't be access from child class.
}
$recentUser = new RecentUser;
?>
<!DOCTYPE html>
<html>
<head>
<title>Object Oriented Programming in php</title>
</head>
<body>
<h4>Here I practiced about oop in php.</h4>
<p>Output the public method from the parent class: <b><?= $recentUser->showUserName();?></b></p>
<p>Output protected method from the parent class: <b><?= $recentUser->showUserMobile();?></b></p>
<p>Private method can't call from the child class. But it can be called from the same class.</p>
<?php
$value = $forceUser->userDetails();
foreach($value as $val){
?>
<p><?= $val;?></p>
<?php
}
?>
</body>
</html>