Suppose, the parent class has
<code>protected $info = ''; public function info() { $this->info = 'xxxx'; } </code>
Subcategories include
<code>echo $this->info; </code>
How to automatically execute the parent class's info() without changing the subclass code, so that the subclass can obtain the effect of $this->info ='xxxx'?
Suppose, the parent class has
<code>protected $info = ''; public function info() { $this->info = 'xxxx'; } </code>
Subcategories include
<code>echo $this->info; </code>
How to automatically execute the parent class's info() without changing the subclass code, so that the subclass can obtain the effect of $this->info ='xxxx'?
There are basically no programming languages with automatic execution solutions, because programming is done according to the programmer's wishes. Even if there is so-called "automatic execution" or "automatic completion", it is completed under the instruction or implementation of the programmer.
If you insist on achieving the effect you want without modifying the subclass, why not just set protected $info
to xxxx
?
If you have any difficulties and cannot set the value of $info
at the beginning, you can also consider the magic method.