I'm wondering if this was possible and I could not find a way to do it so I ask. How can I get the name of the variable where in a instance of a class is present.
Pseudo code:
class test{ public $my_var_name = ''; function __construct(){ //the object says: Humm I am wondering what's the variable name I am stored in? $this->my_var_name = get_varname_of_current_object(); } } $instance1 = new test(); $instance2 = new test(); $boeh = new test(); echo $instance1->my_var_name . ' '; echo $instance2->my_var_name . ' '; echo $boeh->my_var_name . ' '; The output would be like:
instance1 instance2 boeh Why! Well I just wanna know its possible.