gazever Posted November 26, 2009 Share Posted November 26, 2009 Hi what am I doing wrong here Just trying to learn and use classes class form{ var $variable1 = 'test string here'; function return_form(){ return $this->$variable1; } } $test = new form; $theform = $test->return_form(); echo $theform; Link to comment https://forums.phpfreaks.com/topic/183042-classes/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2009 Share Posted November 26, 2009 There is an extra $ in the following line - return $this->$variable1; It should be - return $this->variable1; I'm assuming that you are developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON so that php will alert you to problems is finds (there would have been an error on the line posted above that would have helped you in finding the problem with that line of code.) Link to comment https://forums.phpfreaks.com/topic/183042-classes/#findComment-966029 Share on other sites More sharing options...
gazever Posted November 29, 2009 Author Share Posted November 29, 2009 Yes I have all errors on, what you pointed out was what I was missing, been coding normal PHP for a couple of years, now trying to include classes as part of my coding practices, more learning curves. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/183042-classes/#findComment-967626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.