I've this trait class:
trait Example
{
protected $var;
private static function printSomething()
{
print $var;
}
private static function doSomething()
{
// do something with $var
}
}
And this class:
class NormalClass
{
use Example;
public function otherFunction()
{
$this->setVar($string);
}
public function setVar($string)
{
$this->var = $string;
}
}
But i'm getting this error:
Fatal error: Using $this when not in object context
.
How can i solve this issue? I can't use properties on a trait class? Or this isn't really a good practice?