Variables in classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • moeFinley

    #1

    Variables in classes

    How can I pass a variable out of a class?

    I'm sure this is very simple, but I can't find out how. I think you put a
    charater in front of the variable name, is this right?

    Thanks for any help
    Moe
  • Chris Mosser

    #2
    Re: Variables in classes



    "moeFinley" <moesnews@bluey onder.co.uk> wrote in message
    news:Xns93DA9A4 AE64BDmoesnewsb lueyonderco@194 .117.133.134...[color=blue]
    > How can I pass a variable out of a class?
    >
    > I'm sure this is very simple, but I can't find out how. I think you put a
    > charater in front of the variable name, is this right?
    >
    > Thanks for any help
    > Moe[/color]


    I'm new to php oop also..but I can think of 2 ways to do this.

    A: member vars in php are considered public as far as I know, so you should
    be able to access them directly..i.e.
    $blah = class::blah;
    or
    $blah = $class_Instance -> blah;

    B: Include a getter method in your class description
    $blah = $Instance -> getBlah();

    someone please correct me if I'm wrong

    cmosser


    Comment

    • matty

      #3
      Re: Variables in classes

      Chris Mosser wrote:
      [color=blue]
      > A: member vars in php are considered public as far as I know, so you
      > should be able to access them directly..i.e.
      > $blah = class::blah;[/color]

      This only works for class methods in php (certainly in v4)[color=blue]
      > or
      > $blah = $class_Instance -> blah;[/color]

      This is the solution I posted for him in another group - he's asked this
      question in multiposts everywhere!
      [color=blue]
      >
      > B: Include a getter method in your class description
      > $blah = $Instance -> getBlah();[/color]

      Best way, yes, but I guess telling him this answer would then give rise
      to "What is a getter/setter method"!...

      Matt

      Comment

      Working...