473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Returning References

according to the php manual, it said:

Do not use return-by-reference to increase performance, the engine is
smart enough to optimize this on its own.

I doubt if this only apply to the PHP5 engine, while if I am using
PHP4, performance is a factor to continue to use return by refercnece?

Jan 1 '07 #1
3 1273
howa wrote:
according to the php manual, it said:

Do not use return-by-reference to increase performance, the engine is
smart enough to optimize this on its own.

I doubt if this only apply to the PHP5 engine, while if I am using
PHP4, performance is a factor to continue to use return by refercnece?
Even in PHP 4 you won't find a significant difference (if any) between
return by reference and return by value.

If you're having performance problems, I'd suggest doing some debugging
to figure out where the problems really are.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 1 '07 #2
according to the php manual, it said:
>
Do not use return-by-reference to increase performance, the engine is
smart enough to optimize this on its own.

I doubt if this only apply to the PHP5 engine, while if I am using
PHP4, performance is a factor to continue to use return by refercnece?
No, return by reference will not increase performance even in PHP4,
unless you're using a really huge variable with MBs of data, that is
not the common case.

Using references without a technical reason to do that (when you really
need a reference to be returned) wil only cause unecessary annoyances
to the coders.

Remember to mantain your code as simple as possible while this practice
will not cause any perceptible performance or other issues.

Also, its important to say that normally the principal bottleneck in a
common PHP application is the Database, that eventually need a fine
tuning. PHP performance is easily solved using an opcode cache
soluction, like APC, that mantain your scripts compiled in memory,
elimitating the compile time when each access is requested to the
webserver.

Best regards,
Alonso

Jan 1 '07 #3
On 31 Dec 2006 20:04:10 -0800, "howa" <ho******@gmail.comwrote:
>according to the php manual, it said:

Do not use return-by-reference to increase performance, the engine is
smart enough to optimize this on its own.

I doubt if this only apply to the PHP5 engine, while if I am using
PHP4, performance is a factor to continue to use return by refercnece?
This does apply to PHP4. zend.com seem to have rearranged their site which has
made an article on this disappear but it's still available from archive.org:

http://web.archive.org/web/200604271.../ref-count.php

From PHP4, assignments are always done by reference initially, and the work of
doing a copy is only done when the new variable is _modified_. Using references
(excessively) actually ends up doing slightly more work. When you return a
large string value from a function without return-by-reference then it doesn't
start making copies of it - the ref-counting mechanism is supposed to be "smart
enough" to avoid this.

The exception is for objects where you do want (almost) every assignment to be
a reference in PHP4 - but not in PHP5.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew Fleet | last post by:
Hi, I'm looking at returning a reference to an array I create within a subroutine. I could do this... sub foo { my @theArray; <snip>
7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
18
by: cppaddict | last post by:
Hi, Is it considered bad form to have the subscript operator return a const reference variable? If not, what is the proper way to do it? My question was prompted by the code below, my...
12
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
2
by: matthias_k | last post by:
Hello, I'm wondering if returning const references to a class member is generally faster than returning a copy of the object. Consider this code: class A { std::string data; public:
10
by: Fraser Ross | last post by:
I need to know the syntax for writing a reference of an array. I haven't seen it done often. I have a class with a member array and I want a member function to return an reference to it. ...
3
by: Alfonso Morra | last post by:
I'm in the process of implementing an abstract factory design pattern for an application. I would like to know, which is the recommended way of returning objects from the factory - by reference or...
7
by: wonderboy | last post by:
Hey guys, I have a simple question. Suppose we have the following functions:- //-----My code starts here char* f1(char* s) { char* temp="Hi"; return temp;
6
by: Derrick | last post by:
Hello all; Since I do have working code, this is more for my curiosity only. I'm creating a "Plugin" architecture, following some of the many examples on the 'net. Basically what I have is...
23
by: pauldepstein | last post by:
Below is posted from a link for Stanford students in computer science. QUOTE BEGINS HERE Because of the risk of misuse, some experts recommend never returning a reference from a function or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.