-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.php
More file actions
executable file
·54 lines (43 loc) · 1.54 KB
/
inheritance.php
File metadata and controls
executable file
·54 lines (43 loc) · 1.54 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
<?php
// Used for perent class method or properties in child class call to inharitance
// I explain with access modifier public, private, protected
// Public access modifier access any where class this access that becouse this public you access child perent both
// private access modifier access only same class not access in child class
// protected access only child class and same class
class Databse { // this is perent class
public function db_connect(){
echo 'Db conection function'.'<br>';
}
private function db_user()
{
echo 'Db connection user function'.'<br>';
}
public function db_password()
{
echo 'Db connection pass function'.'<br>';
return $this->db_user(); //this is private function but access becouse this function in same class
}
protected function db_host()
{
echo 'Db connection pass function'.'<br>';
//return $this->db_user(); //this is protected function but access becouse this function in same class
}
}
class table extends Databse{ // table is child class
public function table_connection()
{
echo 'DB table connection '.'<br>';
return $this->db_connect(); //access perent class funtions called inharit. protected only access child class and perent class
}
public function insertdata()
{
echo 'Insert data connection'.'<br>';
//return $this->db_user(); // this access private function. they can not access becouse this is private. so private function not access an other class
}
public function conn(){
return $this->db_host();
}
}
$obj = new table();
echo $obj->table_connection();
?>