passing property as an arg. to method???

Discussion in 'PHP' started by gsingla4u, Jul 31, 2010.

  1. gsingla4u

    gsingla4u New Member

    Joined:
    Jul 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    guys how to pass a property as an argument/parameter to a method in same class.
    Coz i think this is not valid:


    Code:
    class A{
                 public $var=4;
           function xyz($this->var){      // invalid way.
               
           }
    }
    
    so is there a way that i can actually pass property to a method ???
     
  2. johnny.dacu

    johnny.dacu New Member

    Joined:
    Jul 6, 2010
    Messages:
    88
    Likes Received:
    4
    Trophy Points:
    0
    Well if you want to use a class property in a method use something like this:
    PHP:
    class A{
    public 
    $var 4;
    public function 
    xyz(){
    $this->var //here you use your variable
    }
    }
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice