eldan88 Posted June 3, 2014 Share Posted June 3, 2014 Hey Guys. I Have a quick questions. I keep getting an "undefined variable" when php parses the following code echo "<div class='menu'>${$this->price}</div>"."<br>"; However when I put a space after the dollar sign it works fine... echo "<div class='menu'>$ {$this->price}</div>"."<br>"; Doesn't the curly braces tells php to seperate strings from variables? I'm a little bit confused. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/288954-undefined-variable/ Share on other sites More sharing options...
Solution Jacques1 Posted June 3, 2014 Solution Share Posted June 3, 2014 (edited) Doesn't the curly braces tells php to seperate strings from variables? No. It tells PHP to interpret $this->price as a variable name: <?php $var_name = 'foo'; $foo = 'bar'; echo "${$var_name}"; // the same as $foo See variable variables. You need to escape the dollar sign, which is good practice anyway. Edited June 3, 2014 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/288954-undefined-variable/#findComment-1481727 Share on other sites More sharing options...
eldan88 Posted June 3, 2014 Author Share Posted June 3, 2014 Okay. I got it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/288954-undefined-variable/#findComment-1481733 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.