AFTNHombre Posted January 12, 2012 Share Posted January 12, 2012 I thought I was a beginner PHPer but now I'm not even sure I'm that. I have this class here which starts with: private static $FormatType = ""; but then further down: public function SetFormatType($NewFormatTypeId) { $this->FormatType = $NewFormatTypeId; } public function GetFormatType() { return $this->FormatType; } Do you suppose that the original developer just had a singleton or something, then latter on he found that he was making more instances and PHP tolerates this behavior? Or am I missing something? Quote Link to comment https://forums.phpfreaks.com/topic/254906-isnt-accessing-a-static-variable-from-a-non-static-function-bad/ Share on other sites More sharing options...
requinix Posted January 12, 2012 Share Posted January 12, 2012 That syntax is bad, yes. Accessing them in general is fine, but the way to do it is self::$FormatType Yes, PHP is tolerating the code, but somewhere it's creating warning messages (even if you can't see them). Quote Link to comment https://forums.phpfreaks.com/topic/254906-isnt-accessing-a-static-variable-from-a-non-static-function-bad/#findComment-1307059 Share on other sites More sharing options...
AFTNHombre Posted January 13, 2012 Author Share Posted January 13, 2012 Actually, there are many instances of this class, so I'd say the bad syntax is in the static keyword. So I guess I'll remove those. In fact, I'm surprised that every time a member is set, it doesn't clobber all the other instances' members. Also, is there something wrong w/the reply notification? I haven't gotten any and I'm expecting several. My account is GMail. Are they blocking phpfreaks? Quote Link to comment https://forums.phpfreaks.com/topic/254906-isnt-accessing-a-static-variable-from-a-non-static-function-bad/#findComment-1307196 Share on other sites More sharing options...
AFTNHombre Posted January 13, 2012 Author Share Posted January 13, 2012 As a matter of fact, they were being quarantined. I'm going to see what I can do about that. Quote Link to comment https://forums.phpfreaks.com/topic/254906-isnt-accessing-a-static-variable-from-a-non-static-function-bad/#findComment-1307254 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.