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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -