Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2248 invoked from network); 8 May 2008 20:08:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 May 2008 20:08:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=truth@proposaltech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=truth@proposaltech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain proposaltech.com from 66.51.199.86 cause and error) X-PHP-List-Original-Sender: truth@proposaltech.com X-Host-Fingerprint: 66.51.199.86 exvs01.ex.dslextreme.net Windows 2000 SP4, XP SP1 Received: from [66.51.199.86] ([66.51.199.86:52672] helo=EXVS01.ex.dslextreme.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/72-23700-BAD53284 for ; Thu, 08 May 2008 16:08:11 -0400 Received: from 69.236.135.99 ([69.236.135.99]) by EXVS01.ex.dslextreme.net ([192.168.7.220]) via Exchange Front-End Server owa.dslextreme.net ([192.168.7.126]) with Microsoft Exchange Server HTTP-DAV ; Thu, 8 May 2008 20:10:49 +0000 Received: from inspiron by owa.dslextreme.net; 08 May 2008 13:08:05 -0700 To: internals In-Reply-To: <021601c8b141$bbf64a50$4001a8c0@foxbox> References: <021601c8b141$bbf64a50$4001a8c0@foxbox> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Thu, 08 May 2008 13:08:05 -0700 Message-ID: <1210277285.8421.23.camel@inspiron.local> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Subject: Re: [PHP-DEV] allow_call_time_pass_reference From: truth@proposaltech.com (Todd Ruth) On Thu, 2008-05-08 at 20:28 +0100, Steph Fox wrote: > ... > Does anyone have a good reason for keeping it switched on by default in PHP > 5.3? Like, would switching it off by default break a lot of existing code, > given that most users are a bit beyond PHP 3 now? Well, I can at least comment on how it is used in the code that I inherited. First it must be noted that the following throws a fatal error: function f(&$x=5) { .... There are functions in our application that will use information if it is available and update the information if it is provided, but don't absolutely require such information in the first place. I don't know of another clean way to do that besides call-time pass-by-reference. Here is a useless example of the functionality. (This is an example, and only an example. In the event of real code, something useful would be accomplished. ;) ) Without call-time pass-by-reference, that becomes: function g(&$x) { if ($x === null) { $x = 5; } if ($x < 10) { print "blue\n"; $x += 10; $retval = true; } else { print "green\n"; $x += 20; $retval = false; } return $retval; } $y = null; g($y); $y = 10; g($y); $y=5; g($y); g($y); So, without call-time pass-by-reference, "if" blocks would be needed to set defaults and temp variables would be needed anywhere an rvalue is used as an argument. It's true that the former has more opportunities for design error and without the comment about $x being received by reference there could be confusion, but going back and changing all that code is not desirable. "Easier to read" is always a tricky argument, but I'm sure many would find the first code above easier to read. - Todd