Topic: PHP Class attribute values (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31573" title="Pages that link to Topic: PHP Class attribute values (Page 1 of 1)" rel="nofollow" >Topic: PHP Class attribute values <span class="small">(Page 1 of 1)</span>\

 
Hustluz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 01-06-2010 05:51

Issue:

I have a user class that has the blueprint to create a new user and inserts its records into the database. One of the attributes is called dateInsterd that logs the creating date and time of creation.

If i set it with a hidden form input and make it the current time sting it works just fine.

but when i set it up in the class ass an attriubute it give e this error

error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'


The Code is this

1. This code works fine

code:
class User {
	public $dtUpdated;
	public $access= 1;
	public $banned = 0;
}



code with error

code:
class User {
	public $dtUpdated = strftime("%Y-%m-%d %H:%M:%S", time());
	public $access= 1;
	public $banned = 0;
}



can someone please tell me why i cant set the date inserted attribute to strftime("%Y-%m-%d %H:%M:%S", time()) in my object class

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-06-2010 09:38

because you can only initialize this kind of attribute to constant values.

Everything else needs to go into a constructor.

Hustluz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 01-06-2010 16:10

I just want to thank you Tyberius Prime very much. It worked perfect i should have thought of that. I noticed you always answer my very quickly with really good advice and i want you to know i appreciate it.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu