php - When to use $this->$property -
i having trouble understanding when , why need use $this->$property. adding $ both the this keyword , property. have seen used within magic methods __get() , __set(). can elaborate?
you can use $this->$property when $property contains name of property or $this->$function() when $function contains function name.
example:
class myclass { private $email = "rr@rr.com"; public function getproperty($p){ return $this->$p; } } $obj = new myclass; $obj->getproperty("email"); // returns rr@rr.com
Comments
Post a Comment