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! Link to comment https://forums.phpfreaks.com/topic/288954-undefined-variable/ Share on other sites More sharing options...
Jacques1 Posted June 3, 2014 Share Posted June 3, 2014 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. 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! Link to comment https://forums.phpfreaks.com/topic/288954-undefined-variable/#findComment-1481733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.