我可以将对象中的方法声明为静态和非静态方法,并且具有调用静态方法的相同名称吗?
我想创建一个具有静态方法"send"的类和一个调用静态函数的非静态方法.例如:
class test {
private $text;
public static function instance() {
return new test();
}
public function setText($text) {
$this->text = $text;
return $this;
}
public function send() {
self::send($this->text);
}
public static function send($text) {
// send something
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在这两个上调用函数
test::send("Hello World!");
Run Code Online (Sandbox Code Playgroud)
和
test::instance()->setText("Hello World")->send();
Run Code Online (Sandbox Code Playgroud)
可能吗?