E_Leeder Posted October 30, 2014 Share Posted October 30, 2014 (edited) 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 October 30, 2014 by E_Leeder Quote Link to comment https://forums.phpfreaks.com/topic/292170-can-you-echo-class-constants/ Share on other sites More sharing options...
NotionCommotion Posted October 30, 2014 Share Posted October 30, 2014 You can't do so with static classes. See http://php.net/manual/en/language.types.string.php#language.types.string.parsing Quote Link to comment https://forums.phpfreaks.com/topic/292170-can-you-echo-class-constants/#findComment-1495287 Share on other sites More sharing options...
E_Leeder Posted October 31, 2014 Author Share Posted October 31, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/292170-can-you-echo-class-constants/#findComment-1495328 Share on other sites More sharing options...
Ch0cu3r Posted October 31, 2014 Share Posted October 31, 2014 Only variables are parsed within double quoted strings. You cannot call a function/constant within a string unless you use concatenation. Quote Link to comment https://forums.phpfreaks.com/topic/292170-can-you-echo-class-constants/#findComment-1495358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.