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!)

i just would like to know the reason why it would create 'multiple copies of the object'.

just practicing my theorizing to udnerstand how they probably did the php 4 code.

 

thanks anyway. i guess php4 is old and shouldnt bother with understanding it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.