I wanted to create a method in the User model that behaves differently when called statically or non-statically. Basically it should do this:
public function foo() {
// based on http://stackoverflow.com/questions/3824143/how-can-i-tell-if-a-function-is-being-called-statically-in-php
if(isset($this) && get_class($this) == __CLASS__) {
$static = true;
} else {
$static = false;
}
if($static)
$user = Auth::user();
else
$user = $this;
// Do stuff with the user
return $user->bar;
// ...
}
But it gives me the error:
Non-static method User::foo() should not be called statically, assuming $this from incompatible context
.