how to get time from php class? -
below part of class file:
class main{ public time; $this->time = gmdate("y-m-d h:i:s",time()+21600); }
but showing following error:
syntax error, unexpected t_variable, expecting t_function in /home/user/folder/main.php on line 3
would tell me how fix it?
you forgot $
time
variable , assignment
of value can in __construct()
function this:
<?php class main { public $time; function __construct() { $this->time = gmdate("y-m-d h:i:s",time()+21600); } } $object = new main(); echo $object->time; ?>
output:
2014-11-27 11:43:36
also know can assign constant values class member in class definition! in constructor can assign whatever want
Comments
Post a Comment