How to define a member variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce W...1

    How to define a member variable?

    PHP barfs (on line 3) when I define a member variable like this:

    class Foo()
    {
    $num;

    function DoSomething()
    {
    $num = 2 + 3;

    }
    }

    I want to do this so I can access if from another function. How can
    this be done?

    Thanks for your help.
  • Tom Thackrey

    #2
    Re: How to define a member variable?


    On 14-Oct-2003, "Bruce W...1" <bruce@noDirect Email.com> wrote:
    [color=blue]
    > PHP barfs (on line 3) when I define a member variable like this:
    >
    > class Foo()
    > {
    > $num;
    >
    > function DoSomething()
    > {
    > $num = 2 + 3;
    >
    > }
    > }[/color]

    class Foo
    {
    var $num;
    function DoSomething()
    {
    $this->num = 2+3;
    }
    }

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Matthias Esken

      #3
      Re: How to define a member variable?

      "Bruce W...1" <bruce@noDirect Email.com> schrieb:
      [color=blue]
      > PHP barfs (on line 3) when I define a member variable like this:
      >
      > class Foo()
      > {
      > $num;
      >
      > function DoSomething()
      > {
      > $num = 2 + 3;
      >
      > }
      > }[/color]

      The syntax has to be like that:

      class Foo() {
      var $num;

      function DoSomething() {
      $this->num = 2 + 3;
      }
      }


      The documentation is here:
      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


      Regards,
      Matthias

      Comment

      • Pedro

        #4
        Re: How to define a member variable?

        Bruce W...1 wrote:[color=blue]
        >PHP barfs (on line 3) when I define a member variable like this:
        >
        >class Foo()
        >{
        > $num;[/color]
        [...]


        maybe

        class Foo()
        {
        var $num;
        // ...
        }

        will do the trick?


        --
        I have a spam filter working.
        To mail me include "urkxvq" (with or without the quotes)
        in the subject line, or your mail will be ruthlessly discarded.

        Comment

        • Bruce W...1

          #5
          Re: How to define a member variable?

          Tom Thackrey wrote:[color=blue]
          >
          > On 14-Oct-2003, "Bruce W...1" <bruce@noDirect Email.com> wrote:
          >[color=green]
          > > PHP barfs (on line 3) when I define a member variable like this:
          > >
          > > class Foo()
          > > {
          > > $num;
          > >
          > > function DoSomething()
          > > {
          > > $num = 2 + 3;
          > >
          > > }
          > > }[/color]
          >
          > class Foo
          > {
          > var $num;
          > function DoSomething()
          > {
          > $this->num = 2+3;
          > }
          > }
          >
          > --
          > Tom Thackrey
          > www.creative-light.com
          > tom (at) creative (dash) light (dot) com
          > do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)[/color]

          =============== =============== =============== ==

          That seems to work. Thanks guys!

          Comment

          Working...