SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast dave_merwin's Avatar
    Join Date
    Apr 2003
    Location
    Eugene, OR
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question In a class what does var do?

    In the following sample what does var do?

    PHP Code:
    class someclass {

    var 
    $something;


    Does it instantiate the variable?

    Wouldn't you just say the following to make it exist?

    PHP Code:
    class someclass {

    $something;


    I am really confused.
    Dave Merwin

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You declare variables that way. By doing that outside you make the variable accessible from any method inside the class:

    PHP Code:

    class Something {

    var 
    $something;

    function 
    Something($something)
    {

    $this->something $something;

    }

    function 
    somethingElse()
    {

    //look i can access that variable from here
    return $this->something;
    }


    Silly

  3. #3
    SitePoint Enthusiast dave_merwin's Avatar
    Join Date
    Apr 2003
    Location
    Eugene, OR
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I am not sure I get it.

    I'm sorry, but I just got the anthology (PHP ANTHOLOGY). I do not understand your example. To save you all the hard work... is this correct?

    Class = stores many functions and methods
    Function = does one thing
    Method = the way that thing is done

    My comments are in your code.

    Quote Originally Posted by Sillysoft
    PHP Code:

    class Something {

    var 
    $something//Make teh variable accesable?

    function Something($something)
    {

    $this->something $something//This version of teh var something is something?

    }

    function 
    somethingElse() //new function
    {

    //look i can access that variable from here
    return $this->something//stop the script and get $something?
    }


    Is that right?
    Dave Merwin


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •