I am trying to make it so that I can call a non-static method statically using __callStatic but I keep getting this error. I know it is possible because some frameworks (like Laravel) does this but I can't seem to be able to do it myself.
Fatal error: Uncaught Error: Using $this when not in object context in Output.php:18 Stack trace: index.php(4): Output::prepare() 1 {main} thrown in Output.php on line 14
index.php
$output = Output::prepare();
Output.php
class Output
{
public static function __callStatic($method, $args)
{
if ($method == 'prepare') {
$obj = new static();
return $obj->$method(...$args);
}
}
public function prepare()
{
// (!) Uncaught Error: Using $this when not in object context
if ($this->hasItems()) {
return print_r($_POST, true);
}
}
public function hasItems()
{
return true;
}
}