TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Overriding & Overloading Example using PHP
Bhushan Singh
Jan 27
2016
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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