ngloosh Posted August 3, 2008 Share Posted August 3, 2008 I just got started w/ OSCommerce and PHP, and I'm puzzled abt an error PHPEclipse is giving me: Parser Error ";' expected after field declaration. See Line "var $cookie_path: class php3session { var $name = PHP_SESSION_NAME; var $auto_start = false; var $referer_check = false; var $save_path = PHP_SESSION_SAVE_PATH; var $save_handler = 'php3session_files'; var $lifetime = 0; var $cache_limiter = 'nocache'; var $cache_expire = 180; var $use_cookies = true; var $cookie_lifetime = 0; var $cookie_path = substr(DIR_WS_ADMIN, 0, -1); var $cookie_domain = ''; var $gc_probability = 1; var $gc_maxlifetime = 0; var $serialize_handler = 'php'; var $ID; var $nr_open_sessions = 0; var $mod_name = ''; var $id; var $delimiter = "\n"; var $delimiter_value = '[==]'; function php3session() { $this->mod_name = $this->save_handler; } } The substr() function is the issue. I can't call ANY function and set it to the class variable. Seems like it has to be a static variable. Any workarounds? Link to comment https://forums.phpfreaks.com/topic/117999-class-variables/ Share on other sites More sharing options...
DarkWater Posted August 4, 2008 Share Posted August 4, 2008 First of all, why are you using the deprecated PHP 4 OOP syntax? Second of all, just define it in the constructor. Link to comment https://forums.phpfreaks.com/topic/117999-class-variables/#findComment-607088 Share on other sites More sharing options...
Stooney Posted August 4, 2008 Share Posted August 4, 2008 In php, when a class variable is declared, it's value cannot be the result of a calculation of any sort. (I think my wording is right there). So public $var=1+1; that is wrong As darkwater said, you could do it in the constructor or something like this: var $cookie_path; $this->cookie_path= substr(DIR_WS_ADMIN, 0, -1); Link to comment https://forums.phpfreaks.com/topic/117999-class-variables/#findComment-607201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.