call class non static methods in static function php code example
Example: php call non static method from static method
class Foo {
private $foo;
private $bar;
public function __construct($foo, $bar)
{
$this->foo = $foo;
$this->bar = $bar;
}
public function fun1()
{
return $this->foo . ' - ' . $this->bar;
}
public static function fun2($foo, $bar)
{
return (new self($foo, $bar))->fun1();
}
}
echo Foo::fun2('foo', 'bar');