Jump to content

why php4 needed 'return by reference (&) to avoid multiple copies of the object'


arianhojat

Recommended Posts

i was reading a php tutorial on this site and wanted to understand why in php4 u had to use pass by reference when creating an object?...

like so...

 

"$someVariable = &new SomeClass;

Note: PHP 4 requires that you use return by reference (&) to avoid multiple copies of the object."

 

i was wondering exactly why pass by reference was needed and not anymore. All i know about 'pass by reference' is that for example when u pass an object with it to a function, it passes a reference to the object so function can modified it.

 

In PHP4, when objects were created on the right hand side with new SomeClass, did the left hand side not know to take in that exact object reference? like Did it pass a copy of it to it, hence creating 2 objects and only the copied one is referenced, the other orig one lies somewhere in memory?

 

(those are the lines of thinking i am trying to figure out why it was needed, so if you can help out, thanks!)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.