1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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