Jump to content

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


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?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.