Hello
Is it possible to rewrite /replace a protected method in the extended class, in php?
PHP - Rewrite protected method in extended class
-
- Posts: 107
PHP - Rewrite protected method in extended class
Admin
Hello
Yes, you can change the protected attribute of the method in the extended class:
In the same way, you can rewrite the protected method, maintaining the same attribute:
Yes, you can change the protected attribute of the method in the extended class:
Code: Select all
class A {
protected function f1(){
return 'abc';
}
}
class B extends A {
public function f1(){
return 'xyz';
}
}
$ob = new B;
echo $ob->f1(); // xyz
Code: Select all
class A {
protected function f1(){
return 'abc';
}
}
class B extends A {
protected function f1(){
return 'xyz';
}
public function f2(){
return 123 . $this->f1();
}
}
$ob = new B;
echo $ob->f2(); // 123xyz
Similar Topics
-
Venice protected from flooding by new Mose flood barrier
Remarkable News
First post
A long-delayed flood barrier successfully protected Venice from a high tide for the first time on Saturday, bringing relief and smiles to the lagoon...Last post
MOSE, a system of 78 hydraulic gates, once again proved its effectiveness on Thursday 15-10-2020, saving Venice from a tide that Italian officials... -
Php Class COM not found
PHP - MySQL
First post
I've been trying to use the PHP COM class in my script:Last post
$voice = new COM('SAPI.SpVoice');
but I get receiving the following error.
Fatal...
From PHP 5.4.5, COM and DOTNET is no longer built into the php core.
You have to add COM support in php.ini. Add the following code to the end of...