class Foo {
private $_id;
public function __construct (){
$this->_id = /*requesting variable name*/;
}
}
$bar = NEW Foo();
I’m trying to set the $bar->_id equal to ‘bar’
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no other sane way to do this.
An object is the object. It has no relationship to the variable it’s assigned to. You cannot get the name of the variable the object has been assigned to inside the object. Consider that an object may not be assigned to a variable at all, or it may be assigned to several variables at the same time, or the variable it’s assigned to may change.