ksmatthews Posted February 6, 2009 Share Posted February 6, 2009 Hi All, I recently took a php test and this question came up ... What is the difference between $beer and $$beer ? Both seem legal to me .... Steven Matthews Link to comment https://forums.phpfreaks.com/topic/144040-variable-declaration/ Share on other sites More sharing options...
redarrow Posted February 6, 2009 Share Posted February 6, 2009 variable variable. http://uk.php.net/language.variables.variable Link to comment https://forums.phpfreaks.com/topic/144040-variable-declaration/#findComment-755766 Share on other sites More sharing options...
ksmatthews Posted February 6, 2009 Author Share Posted February 6, 2009 what is point of having Variable variables ? What can they be used for ? Steven Matthews Link to comment https://forums.phpfreaks.com/topic/144040-variable-declaration/#findComment-755780 Share on other sites More sharing options...
Mark Baker Posted February 6, 2009 Share Posted February 6, 2009 what is point of having Variable variables ? Use... depends on circumstance as to whether you'll ever actually need them, but they're a tool that's available for you to use or not as you choose. $DUFF = "Homer's Favourite"; $beer = 'DUFF'; echo $$beer.' is '.$beer; Link to comment https://forums.phpfreaks.com/topic/144040-variable-declaration/#findComment-755811 Share on other sites More sharing options...
Mark Baker Posted February 6, 2009 Share Posted February 6, 2009 Better example: class myClass { private $data1 = 1; private $data2 = 2; public function __get($name) { return $this->$$name; } } $instance = new myClass(); echo $instance->__get('data1'); Link to comment https://forums.phpfreaks.com/topic/144040-variable-declaration/#findComment-755832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.