If PHP always copies objects by reference, what happens if an object created in a method is assigned to a member variable? -


I am confused about what will happen in this situation:

  public function foo () {$ Obj = new \ stdClass (); $ Obj- & gt; Bar = 'fubar'; $ This- & gt; Obj = $ obj; }  

If $ obj is copied from the reference, then when foo () returns, then $ Obj can be removed and thus $ this-> obj point to an object that no longer exists?

In the method it looks like this:

  $ obj - --------. & Gt; - [object] $ this- & gt; Obj - ' 

When the method return $ obj variable is lost, and $ This-> Obj will still point to the object:

  $ this-> obj ------> [Object]  

[object] The price will only disappear (or the garbage can be collected), once all the references have been removed.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -