Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Overriding & Overloading Example using PHP
WhatsApp
Bhushan Singh
Jan 27
2016
1.3
k
0
0
class
parentclass {
function
name() {
return
'Parent'
;
}
}
class
childclass
extends
parentclass {
function
name() {
return
'Child'
;
}
}
$obj
=
new
childclass();
echo
$obj
->name();
//It called child function instead of parent parent function - Overriding Example
class
testclass {
public
$data
;
public
function
__get(
$name
) {
echo
"Getting '$name'\n "
;
return
$this
->data[
$name
];
}
}
$obj
=
new
testclass();
/** Magic method Example * */
echo
$obj
->b;
//As __get function called - Overloading example 2
/** Magic method Example * */
Overriding
Overloading
php
Up Next
Overriding & Overloading Example using PHP