OOP question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

OOP question

Post by Fredix »

Hi,
just a little thing:

You declare variables in a class like

var $myvar;

and access them like $this->myvar.

Now I've seen someone using a variable in a function (method) of a class without $this->.

Is this generally wrong, or is it allowed when you use that variable only inside that function?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you're only going to use that variable within that method then you don't need to use $this->. Not all variables will need to be accessible globally within the class.

Mac
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post by Fredix »

exactly what I wanted!

Thank you very much!
Post Reply