Jump to content

Can you echo class constants?


E_Leeder

Recommended Posts

Can you echo class constants?
This does not work for me.

echo “here is a class constant: self::CLASS_CONSTANT”; // using double quotes

Instead I *must* concatenate it:

echo ‘here is a class constant: ‘ . self::CLASS_CONSTANT;

But of course I do not have to do this with a normal variable, which will echo a variable fine:

echo “my name is $name_variable”;

Am I doing something wrong or is this normal behavior?

Link to comment
https://forums.phpfreaks.com/topic/292170-can-you-echo-class-constants/
Share on other sites

I read through the link but I think I missed it where it says you can't echo class constants within static clases. Could you please point me to where it indicates that? I found something like it mentioned for curly syntax variables, but I don't think it applied to my case, and I am looking for better understanding.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.