I want to access to a property whose name is stored in a const.
class Foo
{
const PROPERTY_NAME = 'bar';
protected $bar;
public function getBar() {
return $this->self::PROPERTY_NAME;
}
}
Any idea on how to do this ?
Try this:
class MyClass
{
const MYCONSTANT = 'constant value';
function showConstant() {
echo self::MYCONSTANT. "
";
}
}
$classname = "MyClass";
echo $classname::MYCONSTANT. "
"; // As of PHP 5.3.0
// Output: constant value