Sheldon Cooper
Sheldon Cooper

Reputation: 246

How to call class constant value in this case

suppose i need to get value which is formed dynamically like

StaticClass::chatincon

is formed using dyanmic part $aa

$aa = icon;
echo StaticClass::chat{$aa}; // not working

what's the correct way to preferably without use of eval() // as eval r subjected to eval injection

Upvotes: 1

Views: 91

Answers (3)

Linga
Linga

Reputation: 10573

You missed the constant . The syntax is

constant ( string $name )

It should be

constant('StaticClass::chat'. $aa)

Upvotes: 1

Justin T.
Justin T.

Reputation: 3701

Use function constant() (as in http://www.php.net/constant) i.e :

constant('StaticClass::chat'. $aa)

Upvotes: 1

deceze
deceze

Reputation: 522636

constant("StaticClass::chat$aa")

http://php.net/constant

And constants aren't "called", they're "accessed" if anything.

Upvotes: 1

Related Questions