I am working on a PHP library in Laravel. I want to call a variable that is global to my function and I get this error.
Using $this when not in object context
Where am I missing?
class ConfigurationProvider implements ConfigurationProvider
{
protected $conf;
private function getCredentials()
{
return $this->conf;
}
}
My Controller
public function testApi(){
$object = ConfigurationProvider::getCredentials();
return $object;
}
2
Answers
Instantiate your object, then call the method
You’re treating
getCredentials()
as a static method. Static method do not have access to the object. Just static properties.