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: 
> 
> Can I access the value of MY\_CONST somehow?
> 
> 
> 

```
self::MY_CONST

```

If you want to access is dynamically, you can use the [reflection API *Docs*](http://php.net/manual/en/book.reflection.php):

```
$myvar = 'MY_CONST';
$class = new ReflectionClass(self);
$const = $class->getConstant($myVar);

```

The benefit with the reflection API can be that you can get all constants at once (`getConstants`).

If you dislike the reflection API because you don't wanna use it, an alternative is the `constant` function ([Demo](http://codepad.viper-7.com/0DORea)):

```
$myvar = 'MY_CONST';    
class foo {const MY_CONST = 'bar';}    
define('self', 'foo');    
echo constant(self.'::'.$myvar);

```
have you tried 

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

```