php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54870 References Comment Should be Removed
Submitted: 2011-05-20 07:42 UTC Modified: 2011-07-02 18:41 UTC
From: miqrogroove at gmail dot com Assigned: frozenfire (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: miqrogroove at gmail dot com
New email:
PHP Version: OS:

 

 [2011-05-20 07:42 UTC] miqrogroove at gmail dot com
Description:
------------
I've done some testing of variable reference behavior in PHP and was able to 
disprove something in the documentation.  On the manual page at

http://php.net/manual/en/functions.arguments.php

there is a comment that says, "Note that passing by reference doesn't speed up 
your php script. PHP is smart enough not to simply copy data every time the 
language requires it. Rahter, PHP uses a reference and waits until the copy (a 
copied variable or a copy used in a function) is actually used as a copy and 
creates one then."

That statement is not correct in any circumstance I could come up with, except 
for a read-only function accepting a one megabyte string argument.  I observed 
massive performance improvements when using references to prevent the copy-on-
write behavior.  So, to say that passing by reference doesn't speed up your php 
script is not correct.  It is only correct to say that if a parameter is passed 
by value and never modified, then PHP wont make an extra copy of it.

Test script:
---------------
Details posted at http://www.miqrogroove.com/writing/php-references-for-speed/


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-02 18:26 UTC] frozenfire@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: frozenfire
 [2011-07-02 18:26 UTC] frozenfire@php.net
While I recognize that using references in the way that you suggest could provide 
some performance increase, I think that for the most purposes, it's not worth the 
complexity increase to do so. Doing this is a sort of premature optimization, so 
it's something that most users of PHP should avoid. As such, I'm inclined to keep 
the quoted text, because it is *pragmatically correct*, even if it's technically 
incorrect on some level.
 [2011-07-02 18:41 UTC] frozenfire@php.net
-Status: Feedback +Status: Closed
 [2011-07-02 18:41 UTC] frozenfire@php.net
I asked a few people for comments regarding this, and the prevailing opinion 
matches my previous comment. While I applaud your investigation of the nuances of 
the copy-on-write functionality, I'll be marking this bug closed, unless someone 
disagrees.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 05:00:01 2026 UTC