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. Quote Link to comment 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. Quote Link to comment 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 = ""; Quote Link to comment 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. =) Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.