In my class I am using a trait called PlankMediable
that has a method public static function bootMediable()
.
Unfortunately, my class also has a method called protected static function bootMediable()
.
- How do I alias the class as once is public static and the other is protected static? Will this work?
use PlankMediable {
PlankMediable::bootMediable as PlankMediable_bootMediable;
}
- How do I call the static method from my classes
protected static function bootMediable()
class?
CodePudding user response:
Yes, you can define an alias with use. Take a look at the following example:
trait SayWorld {
public static function sayHello() {
echo __METHOD__." from trait";
}
}
class MyHelloWorld {
use SayWorld{
SayWorld::sayHello as traithello;
}
public static function sayHello() {
echo __METHOD__." from class";
}
public static function callFromTrait() {
self::traithello();
}
}
MyHelloWorld::traithello(); //SayWorld::sayHello from trait
MyHelloWorld::sayhello(); //MyHelloWorld::sayHello from class
MyHelloWorld::callFromTrait(); //SayWorld::sayHello from trait