blueteck blueteck - 10 months ago 45
PHP Question

PHP access dynamic attribute from constant content

I want to access a dynamics attribute with the name of the content of a constant. Like

just the other way around.

This is working, but I am wondering is there is something simpler (without

const CONST_1 = 'var_1';
$this->var_1 = 'Hello World';

$varnam = CONST_1;
echo $this->$varnam;


Beside my initial comment :

You can do

echo $this->{CONST_1}

if this is what you are looking for