blueteck blueteck - 2 years ago 87
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;

Answer Source

Beside my initial comment :

You can do

echo $this->{CONST_1}

if this is what you are looking for

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download