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? Quote 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")); } Quote 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. Quote 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 Quote 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(); } Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.