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?

Edited by E_Leeder
Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.