arianhojat Posted February 2, 2007 Share Posted February 2, 2007 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!) Quote Link to comment Share on other sites More sharing options...
arianhojat Posted February 5, 2007 Author Share Posted February 5, 2007 bump Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 5, 2007 Share Posted February 5, 2007 i wouldnt have a clue about this... but i am curious as to why you want to no... Quote Link to comment Share on other sites More sharing options...
arianhojat Posted February 5, 2007 Author Share Posted February 5, 2007 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 lol, thats what i believe. where up to 5 now, learn about that instead. Quote Link to comment Share on other sites More sharing options...
Jenk Posted February 6, 2007 Share Posted February 6, 2007 You no longer need to specify 'pass by reference,' because PHP5 now passes all objects by reference. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 that wasnt the reason this was started. i was wondering exactly why pass by reference was needed and not anymore. that was the base of the question. Quote Link to comment Share on other sites More sharing options...
Jenk Posted February 6, 2007 Share Posted February 6, 2007 er.. ok then.. if that direct, exact, and factual answer will not do, how about: It's because Gallileo had not finished counting all the stars. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 6, 2007 Share Posted February 6, 2007 Because the programmers said so. You might as well ask, "How come in PHP5 you no longer need to specify return by reference when dealing with objects?" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.