prezident Posted January 10, 2011 Share Posted January 10, 2011 This is a simple php class code it worked for me before but i don't know what's wrong with it now This is a little test code to help me understand classes alittle better and i can't get it to work grrrr class person { private $name; function setname($name){ $this->name=$name; } function getname($name){ return $this->$name; } }; $prezident = new person(); $prezident->setname('prezident'); $dayday = new person(); $dayday->setname('dayday'); print $dayday->getname()."<br/>"; print $prezident->getname()."<br/>"; Link to comment https://forums.phpfreaks.com/topic/223961-simple-php-class-code/ Share on other sites More sharing options...
the182guy Posted January 10, 2011 Share Posted January 10, 2011 When referencing properties of a class you don't use the $ sign, so change this: return $this->$name; to return $this->name; Link to comment https://forums.phpfreaks.com/topic/223961-simple-php-class-code/#findComment-1157387 Share on other sites More sharing options...
prezident Posted January 10, 2011 Author Share Posted January 10, 2011 Thank Guy It kills me when the problem is as simple as a $ or not closing a bracket..... Works perfectly fine now... Link to comment https://forums.phpfreaks.com/topic/223961-simple-php-class-code/#findComment-1157389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.