JustinK101 Posted October 11, 2010 Share Posted October 11, 2010 I have the following simple class: class Settings { public static $mysql_datetime_format = "%c/%e/%Y %l:%i %p " . date("[T]"); } And referencing like: echo Settings::$mysql_datetime_format; But, I am getting the error: Parse error: syntax error, unexpected '.', expecting ',' or ';'. Why is this invalid? Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/ Share on other sites More sharing options...
joel24 Posted October 11, 2010 Share Posted October 11, 2010 surround the new value of the variable in brackets, and also you don't need the square brackets around T in the date function. i.e. class Settings { public static $mysql_datetime_format = ("%c/%e/%Y %l:%i %p " . date("T")); } Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1120999 Share on other sites More sharing options...
ignace Posted October 11, 2010 Share Posted October 11, 2010 You can't have a function in a class variable declaration. Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1121166 Share on other sites More sharing options...
rwwd Posted October 11, 2010 Share Posted October 11, 2010 You can't have a function in a class variable declaration. This one has bugged me since it came on, but for the life of me I couldn't put my finger on what was wrong with it, if your right Ignace (which I don't doubt you are) Do I feel stoopid - or what, doh.. Rw Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1121220 Share on other sites More sharing options...
ignace Posted October 12, 2010 Share Posted October 12, 2010 You can't have a function in a class variable declaration. This one has bugged me since it came on, but for the life of me I couldn't put my finger on what was wrong with it, if your right Ignace (which I don't doubt you are) Do I feel stoopid - or what, doh.. Rw stoopid, no - unexperienced, maybe PHP != Java You can't do this for example in PHP: public class SomeJavaClass { private SomeJavaClass parent = new SomeJavaClass(); } Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1121379 Share on other sites More sharing options...
rwwd Posted October 12, 2010 Share Posted October 12, 2010 stoopid, no - unexperienced, maybe PHP != Java Cheers! No, tiredness (masquerading as stupidity!) - I concede that. Rw Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1121382 Share on other sites More sharing options...
ignace Posted October 12, 2010 Share Posted October 12, 2010 stoopid, no - unexperienced, maybe PHP != Java Cheers! No, tiredness (masquerading as stupidity!) - I concede that. Rw Just a joke rwwd Link to comment https://forums.phpfreaks.com/topic/215596-class-member-static-variable-cant-append/#findComment-1121415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.