if a constant is defined in class like this:
class Example
{
const MIN_VALUE = 0.0; // RIGHT - Works INSIDE of a class definition.
}
it is possible to access the constant like this:
Example::MIN_VALUE
but if you do this:
class Sample {
protected $example;
public function __construct(Example $example){
$this->example = $example;
}
public function dummyAccessToExampleConstant(){
//doesn't work -> syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
if($this->example::MIN_VALUE === 0.0){
}
//this works
$tmpExample = $this->example;
if($tmpExample::MIN_VALUE === 1){
}
}
}
Can somebody explain me the reason of this behaviour ?
Is there a good reason or is it just a language construct that prevents the access with "::"
Is there a way how to access a constant with "$this"