-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverriding.php
More file actions
executable file
·31 lines (22 loc) · 896 Bytes
/
overriding.php
File metadata and controls
executable file
·31 lines (22 loc) · 896 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
// function overriding is a feature that allows a child class to provide its own implementation of a method that is already defined in its parent class.
//This allows the child class to override the behavior of the parent class method with its own implementation.
class Databse { // this is perent class
public function db_connect(){
echo 'Db conection function'.'<br>';
}
}
class table extends Databse{ // table is child class
public function db_connect() // define same class in parent and child so this is overriding becouse this function allready difine in parent class
{
//Parent::db_connect();
echo 'DB table connection '.'<br>';
}
public function insertdata()
{
$this->db_connect(); //if this function call in own class becouse this preferred in our class if is not define then called parent function
}
}
$obj = new table();
echo $obj->insertdata();
?>