I have a method/function of a virtual attribute in Model1
:
class Model1 {
public $virtattr;
public $_virtattr;
public function getVirtattr () {
if (isset($this->_virtattr)) {
return $this->_virtattr;
}
return $this->_virtattr = str_ireplace('x1', 'x2', $this->virtattr);
}
}
How can I call this method in Model2
to get the same result?
I was trying it this way but unfortunately it's not working, 'cause I'm getting empty results:
use Model1;
class Model2 {
public $virtattr;
public $_virtattr;
public function getVirtattr () {
return (new Model1)->getVirtattr();
}
}
Can you please point me to the right direction?