RIRedinPA Posted January 3, 2011 Share Posted January 3, 2011 I am getting the following error: Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /Library/WebServer/Dev/classtest/lib/class_userdata.php on line 5 on this class code: class userdata { public $name = ""; public $city = ""; public $phone = ""; function setData($n, $c, $p) { $name = $n; $city = $c; $phone = $p; } function getData() { $userdata=array('name'=>$name, 'city'=>$city, 'phone'=>$phone); return $userdata; } } I thought that was a proper way to set up some class variables. (http://www.victorchen.info/accessing-php-class-variables-and-functions/). Thanks. Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/ Share on other sites More sharing options...
johnny86 Posted January 3, 2011 Share Posted January 3, 2011 There is nothing wrong with your variable declarations, but: Inside a class you need to access the class properties through $this-> or static properties trough self:: class userdata { public $name = ""; public $city = ""; public $phone = ""; function setData($n, $c, $p) { $this->name = $n; $this->city = $c; $this->phone = $p; } function getData() { $userdata=array('name'=>$this->name, 'city'=>$this->city, 'phone'=>$this->phone); return $userdata; } } That would be the appropriate usage of your variables. Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154318 Share on other sites More sharing options...
RIRedinPA Posted January 3, 2011 Author Share Posted January 3, 2011 Thanks for that tip. I changed the code but I keep getting the error message pointing to line 5 - public $name = ""; Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154321 Share on other sites More sharing options...
johnny86 Posted January 3, 2011 Share Posted January 3, 2011 Well all that code is ok and works fine. It must be something else in your code. That can't be the only code in your web application. =) Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154324 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2011 Share Posted January 3, 2011 You are using php5 OOP syntax on a php4 system. The end of life of php4 was several years ago. It is long past time to upgrade to php5. Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154342 Share on other sites More sharing options...
RIRedinPA Posted January 3, 2011 Author Share Posted January 3, 2011 I'll double check with my admin but I am pretty positive we are using PHP 5, not the latest release but definitely 5... Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154360 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2011 Share Posted January 3, 2011 Create a .php script with a phpinfo(); statement and browse to it to find out what version is running. You might have php5, but the version where you are running your code is not. Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154365 Share on other sites More sharing options...
RIRedinPA Posted January 4, 2011 Author Share Posted January 4, 2011 Darn it, stupid sys admin people. Changed everything from public to var and it worked fine. Thanks for the heads up. Link to comment https://forums.phpfreaks.com/topic/223291-php-class-variables/#findComment-1154587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.