Jump to content

class variables?


ngloosh

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.