tags:

views:

62

answers:

2

I have a class definition like:

class JConfig {
    var $offline = '0';
    var $editor = 'tinymce';
    var $list_limit = '20';
    var $helpurl = 'http://help.joomla.org';
    var $log_path = '/path/to/logs';
    // ....
}

I want to dinamically define '$log_path'

I've tried to define a constant outside the class declaration but no look with that

Example:

if(!defined('ROOT_PATH')){
    define('ROOT_PATH', dirname(__FILE__));
}
class JConfig {
    var $offline = '0';
    var $editor = 'tinymce';
    var $list_limit = '20';
    var $helpurl = 'http://help.joomla.org';
    var $log_path = ROOT_PATH . '/logs'; // This generate a error
    // ....
}

But i can not do that, so the question is, is there a way to accomplish this?

A: 

No, you can't use constants or variables in your class property default values. I suggest you just set them in the constructor...

Franz
+3  A: 

You can do it in the class constructor

class JConfig {
    var $offline = '0';
    var $editor = 'tinymce';
    var $list_limit = '20';
    var $helpurl = 'http://help.joomla.org';
    var $log_path;

    public function __construct(){
        $this->log_path = ROOT_PATH . '/logs';
    }
}
Yacoby