Doc #54870 [Opn->Fbk]: References Comment Should be Removed

From: Date: Sat, 02 Jul 2011 22:26:53 +0000
Subject: Doc #54870 [Opn->Fbk]: References Comment Should be Removed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6815@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54870&edit=1 ID: 54870 Updated by: frozenfire@php.net Reported by: miqrogroove at gmail dot com Summary: References Comment Should be Removed -Status: Open +Status: Feedback Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant -Assigned To: +Assigned To: frozenfire Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-05-20 07:42:52] 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/ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54870&edit=1

« previous php.doc.bugs (#6815) next »