E_Leeder Posted October 30, 2014 Share Posted October 30, 2014 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 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 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. 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. 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
Archived
This topic is now archived and is closed to further replies.