rohithreddyk Posted July 12, 2010 Share Posted July 12, 2010 Hi, in my class there is a member variable whose default value contains a "$" character in it.. like private $name = "rohith$kodakandla"; if I use code like this, I am getting an "Unexpected '"' at line..." kind of error. I think the php is taking varible $name as rohith+ value of ( $kodakandla).. i tried removing $ () and It worked perfectly without error. but I want the $name to be "rohith$kodakandla" can someone help me to fix this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/207508-variable-values-containin/ Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 Hi, private $name = 'rohith$kodakandla'; ' -> it doesnt parse the variable or escabe the $ character private $name = "rohith\$kodakandla"; Quote Link to comment https://forums.phpfreaks.com/topic/207508-variable-values-containin/#findComment-1084886 Share on other sites More sharing options...
Barand Posted July 12, 2010 Share Posted July 12, 2010 use single quotes private $name = 'rohith$kodakandla'; or escape the dollar sign private $name = "rohith\$kodakandla"; Quote Link to comment https://forums.phpfreaks.com/topic/207508-variable-values-containin/#findComment-1084888 Share on other sites More sharing options...
rohithreddyk Posted July 12, 2010 Author Share Posted July 12, 2010 thanks a lot barand and bh.. is this double quotes issue version dependent? the reason I am asking is, I came across this issue when debugging an old application that is no longer in use.. i am not sure which version of php they had.. but the current version I am using is 5.1.2 Quote Link to comment https://forums.phpfreaks.com/topic/207508-variable-values-containin/#findComment-1084892 Share on other sites More sharing options...
PFMaBiSmAd Posted July 12, 2010 Share Posted July 12, 2010 Php variables are parsed and replaced with their values when contained within double-quotes AFAIK since the first php version was released and certainly since php 4.0. Quote Link to comment https://forums.phpfreaks.com/topic/207508-variable-values-containin/#findComment-1085002 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.