guest2013-1
guest
- Joined
- Aug 22, 2003
- Messages
- 19,800
- Reaction score
- 13
In the below example, I have a extended a class with the same function showName, when it's public or protected, it will return the extended class' showName instead of the parent class'
I was wondering, how would I be able to run the parent class function and then continue with it in the extended class? (my thoughts in red, can't really test this, at work now and this question is burning)
Will my idea work? Where the parent class' function is called first, processes and returns whatever and then the extended class continues processing it, but when calling the extended class, it will run it's own function instead of it's parents?
I was wondering, how would I be able to run the parent class function and then continue with it in the extended class? (my thoughts in red, can't really test this, at work now and this question is burning)
Code:
<?php
class test {
public function __construct() {
}
public function showName($name) {
echo 'my name in test is '.$name;
}
}
class extendTest extends test {
public function __construct() {
parent::__construct();
}
public function showName($name) {
[color=red]$name = parent::showName($name);[/color]
echo 'this function is run in extendTest and '.$name;
}
}
$test = new extendTest();
$test->name("Joe");
?>
Will my idea work? Where the parent class' function is called first, processes and returns whatever and then the extended class continues processing it, but when calling the extended class, it will run it's own function instead of it's parents?