Support forums : The Future

We Are Doing It Wrong: References

The future of this project but not in a "I want a pony" sort of way. This is all about everything meta about Quam Plures. The general direction, the support tools, stuff like that.

Moderator: Dracones

Re: We Are Doing It Wrong: References

Postby Tblue » Fri Aug 26, 2011 9:47 am

Okay, I'll try to explain it to you. First, I'll give you a link to the official explanation: http://www.php.net/manual/en/language.r ... whatdo.php (or rather a part of it).

So, when we return something by reference we do it in the hope that it'll save us some memory because references only point to the variable and do not contain its contents (which would take up more memory). The same is true for passing by reference.

And that's where we are wrong, as explained in the first post in this thread: PHP is already optimized to save as much memory and CPU time as possible (well, in this case and relatively speaking -- PHP _does_ need its fair share of RAM...).

So, if you return or pass objects, you don't need to use references (at least in PHP 5). If you want to return or pass a reference to a string, for example, you need to use references because strings are not objects.
Tblue
Dracone
 
Posts: 340
Joined: Sat Nov 21, 2009 1:35 pm
Location: Berlin, Germany

Re: We Are Doing It Wrong: References

Postby EdB » Fri Aug 26, 2011 3:13 pm

That is a page I hadn't seen, but I did google it and look for some info on the topic. Kinda got to where you just said: php5 is already on top of it and in general "by reference saves us memory" is both older than and less important than arguing "apple vs pc". So we enjoy php5's smartness and don't pretend we can be smarter than php5 and go with the simplest code we can (by reference only if truly needed), and actually enjoy a faster application.

Well then what I'll try to do is if I do a branch that works in an area that uses & as a by-reference I'll see about if we work without it. Thus working towards not doing that which we don't need to and doesn't help us. The possibility for error goes up when I tinker outside my comfort zone, but code review catches things like that so yay :)
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: We Are Doing It Wrong: References

Postby Tblue » Fri Aug 26, 2011 3:58 pm

Yeah, good idea. :)
Tblue
Dracone
 
Posts: 340
Joined: Sat Nov 21, 2009 1:35 pm
Location: Berlin, Germany

Previous

Return to The Future

Who is online

Users browsing this forum: No registered users and 1 guest

cron