mindspin311 Posted February 7, 2008 Share Posted February 7, 2008 I get: Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /root/test.php on line 13 I just want to make a person object with several variables similar to a struct in c++. First, what's wrong with the code, and 2nd is their an easier way to do this without the set and get functions? I want to do this... struct Person { string id; string name; string score; ..... }; Person bob; bob.id = "1234"; bob.name = "bob"; bob.score = 34; printf( "%s : %s %d",bob.id,bob.name,bob.score); <?php class person { var $m_id = NULL; var $m_name = NULL; var $m_score = NULL; function id() { return this->m_id; } function name() { return this->m_name; } function score() { return this->m_score; } function set_id($id) { this->m_id = $id; } function set_name($name) { this->m_name = $name; } function set_score($score) { this->m_score = $score; } } $bob = new person(); $bob->set_id('123456789'); $bob->set_name('bob'); $bob->set_score(88); echo $bob->id()." (".$bob->name()."): ".$bob->score()." <br>"; ?> Link to comment https://forums.phpfreaks.com/topic/89874-solved-whats-wrong-with-this-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 7, 2008 Share Posted February 7, 2008 Each occurrence of this needs to be $this Link to comment https://forums.phpfreaks.com/topic/89874-solved-whats-wrong-with-this-code/#findComment-460601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.