Tell me, please, is it possible to somehow address the field of a class object, through a field of another class without creating new variables?
Those. Now I have a Test class, in which there is a field named pole_name and the method wokr_object ($ obj) .
The wokr_object method gets the object $ obj , which has a field whose name matches the value stored in the field pole_name .
And I need to access this field in the wokr_object function.
I got this code:
public function wokr_object($obj){ $temp = $this->pole_name; echo $obj->$temp; }
It seems to work, but I do not like that I have to create an additional variable tempo, I want to write something like this in one line.
Those. I want to write something like echo $obj->$this->pole_name
- but it does not work, it displays an error.
Tell me, please, can I somehow fix this, can I somehow arrange the brackets?