I have an object in PHP, of the type MyObject.
$myObject instanceof MyObject
Now, in the class MyObject, there is a non-static function, and in there, I use the reference to “me”, like $this, but I also have another object there.
Is it possible, without doing $this = $myObject, to achieve more or less the same effect, like something of the sort set_object_vars($this, get_object_vars($myObject))?
Will do what you want I guess, but you should be aware of the following:
get_object_varswill only find non-static propertiesget_object_varswill only find accessible properties according to scopeThe according to scope part is quite important and may deserve a little more explanation. Did you know that properties scope are class dependent rather than instance dependent in PHP?
It means that in the example above, if you had a
private $barproperty inMyObject,get_object_varswould see it, since you are in an instance of aMyObjectclass. This will obviously not work if you’re trying to import instances of another class.