Question: I'm trying to access a class constant in one of my classes:

```
const MY_CONST = "value";

```

If I have a variable which holds the name of this constant like this:

```
$myVar = "MY_CONST";

```

Can I access the value of MY\_CONST somehow?

```
self::$myVar

```

does not work obviously because it is for static properties.
Variable variables does not work either.

Answer: 
There are two ways to do this: using the [constant](http://php.net/manual/en/function.constant.php) function or using [reflection](http://www.php.net/manual/en/book.reflection.php).

Constant Function
-----------------

The constant function works with constants declared through `define` as well as class constants:

```
class A
{
    const MY_CONST = 'myval';

    static function test()
    {
        $c = 'MY_CONST';
        return constant('self::'. $c);
    }
}

echo A::test(); // output: myval

```

Reflection Class
----------------

A second, more laborious way, would be through reflection:

```
$ref = new ReflectionClass('A');
$constName = 'MY_CONST';
echo $ref->getConstant($constName); // output: myval

```
have you tried 

```
$myVar = MY_CONST or $myVar = $MY_CONST

```