Re: Which is better, pass, or not pass by reference?
From: odel (b_at_twin-pix.com)
Date: 10/21/03
- Next message: <- Chameleon ->: "Re: resume downloads"
- Previous message: Jon Kraft: "Re: header()"
- In reply to: Randell D.: "Which is better, pass, or not pass by reference?"
- Next in thread: Alan Little: "Re: Which is better, pass, or not pass by reference?"
- Reply: Alan Little: "Re: Which is better, pass, or not pass by reference?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 21 Oct 2003 14:07:39 +0100
Reference is useful only for object.
if your code is object oriented, then you should always return
references to your objects, never copies, or you will have some
surprises (change the object in one place, without changing it somewhere
else is bad)
for built-in types like strings, integers, booleans , return copies, you
will double the use of memory but for this kind of elements, it has
absolutly NO importance (I'm not even sure you can reference a string
for example).
Now even if your code is not OO, you still have some php functions
returning objects i.e. pg_connect, mysql_result... a connection resource
is an object, a resultset is an object, then if you manipulate them or
return them in some functions, return the reference, not the copy.
another good idea to save your memory is to unset your objects once your
done with 'em, like one would do in C++ maybe.
.b
- Next message: <- Chameleon ->: "Re: resume downloads"
- Previous message: Jon Kraft: "Re: header()"
- In reply to: Randell D.: "Which is better, pass, or not pass by reference?"
- Next in thread: Alan Little: "Re: Which is better, pass, or not pass by reference?"
- Reply: Alan Little: "Re: Which is better, pass, or not pass by reference?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|