Reputation: 28354
I'm confused what would happen in this situation:
public function foo() {
$obj = new \stdClass();
$obj->bar = 'foobar';
$this->obj = $obj;
}
If $obj
is copied by reference, then when foo()
returns, won't $obj
be deleted and thus $this->obj
point to an object that no longer exists?
Upvotes: 0
Views: 24
Reputation: 13263
Inside the method this is what it looks like:
$obj ---------.
>-- [OBJECT]
$this->obj --´
When the method returns the $obj
variable is destroyed, and the $this->obj
variable will still point to the object:
$this->obj ------> [OBJECT]
The [OBJECT]
value will only disappear (or be garbage collected) once all references to it have been removed.
Upvotes: 2