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

see: http://php.net/manual/en/language.oop5.properties.php


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -