1

Is the only way to assign $systime a value of a built-in-functions, is through a method?

class Test{ private $systime; public function get_systime(){ $this->systime = time(); } } 

Right off i would think something like this right?:

class Test{ private $systime = time(); public function get_systime(){ echo $this->systime; } } 

Thanks

0

2 Answers 2

2

You should be able to use a constructor to assign the value, for example:

class Test { private $systime; function __construct() { $this->systime = time(); } public function get_systime(){ echo $this->systime; } } $t = new Test(); $t->get_systime(); 

For more information on __construct() see the php manual section on object oriented php.

Sign up to request clarification or add additional context in comments.

Comments

2

From http://www.php.net/manual/en/language.oop5.basic.php (Just before Example 3)

The default value must be a constant expression, not (for example) a variable, a class member or a function call.

However, you can also assign a value from the constructor:

class Test{ private $systime; public function __construct(){ $this->systime = time(); } public function get_systime(){ echo $this->systime; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.