A little confused about calling class variables

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
jonwondering
Forum Commoner
Posts: 39
Joined: Mon Mar 13, 2006 6:26 pm

A little confused about calling class variables

Post by jonwondering »

Okay, if I have:

Code: Select all

class A {
    public $var = 'test';
    function func() {
    }
}
I know I can call A::func(), but can I not call A::var to display the word 'test'? Do I HAVE to create first an object A, and then call it A->var? Or is there a way I just don't know about?
Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: A little confused about calling class variables

Post by Christopher »

You should read this section of the PHP manual:

http://www.php.net/manual/en/language.oop5.php
(#10850)
Post Reply