Dilemma w/ dynamic objects

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ngloosh
Forum Newbie
Posts: 1
Joined: Sun Aug 03, 2008 4:09 pm

Dilemma w/ dynamic objects

Post by ngloosh »

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 16:

Code: Select all

 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;
[color=#FF0000]    var $cookie_path = substr(DIR_WS_ADMIN, 0, -1);[/color]
    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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Dilemma w/ dynamic objects

Post by jaoudestudios »

At the top of the class, you are just declaring the variable as a variable, hence var $cookie_path. Any function you must do in the __construct.

Dont worry we have all been there. :)

I think var is deprecated now, use: public, protected, private depending on what you need to do
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Dilemma w/ dynamic objects

Post by Eran »

What you wrote is a class not an object. A class is a static type declaration while objects can be dynamic. As jaudestudios mentioned, you perform initializing through the __construct method, which is run whenever a class object is instanced. Also he is correct to point out that the syntax you are using is deprecated since PHP 4. If you are using PHP 5 you are better of using visibility syntax to declare class members.
http://www.php.net/zend-engine-2.php
Post Reply