Answer the question
In order to leave comments, you need to log in
How to infiltrate a class?
I am developing for one not very flexible framework the functionality of the so-called. "plugins". I will not describe the functionality in its entirety, I will immediately specify the problem.
Primitive scheme. There is a Component class (the core of the framework). There is a trait PluginTrat (my trait, I can write anything) that is included in the component:
class Component
{
use PluginTrait;
function executeComponent()
{
…
}
}
trait PluginTrait
{
…
}
Answer the question
In order to leave comments, you need to log in
Example #2 , right?
<?php
class Base {
public function sayHello() {
echo 'Hello ';
}
}
trait SayWorld {
public function sayHello() {
parent::sayHello();
echo 'World!';
}
}
class MyHelloWorld extends Base {
use SayWorld;
}
$o = new MyHelloWorld();
$o->sayHello(); // Hello World!
?>
class myComponent extends Component
{
function executeComponent()
{
...
parent::executeComponent();
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question