Jump to content

Isn't accessing a static variable from a non-static function bad?


AFTNHombre

Recommended Posts

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?

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).

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.