Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22999 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68205 invoked by uid 1010); 27 Apr 2006 21:25:07 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 68190 invoked from network); 27 Apr 2006 21:25:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2006 21:25:07 -0000 X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 204.11.219.139 lerdorf.com Linux 2.5 (sometimes 2.4) (4) Received: from ([204.11.219.139:36476] helo=lerdorf.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id ED/D3-11022-2B631544 for ; Thu, 27 Apr 2006 17:25:07 -0400 Received: from [65.74.192.250] (dhcp65-74-192-250.oam.orl.wayport.net [65.74.192.250]) (authenticated bits=0) by lerdorf.com (8.13.6/8.13.6/Debian-1) with ESMTP id k3RLOu4G015160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 27 Apr 2006 14:24:58 -0700 Message-ID: <445136A7.3000801@lerdorf.com> Date: Thu, 27 Apr 2006 17:24:55 -0400 User-Agent: Thunderbird 3.0a1 (Macintosh/20060413) MIME-Version: 1.0 To: Brion Vibber CC: Brian Moon , internals@lists.php.net References: <444FF5CD.2010805@dealnews.com> <444FF716.6070201@lerdorf.com> <44512305.90207@pobox.com> In-Reply-To: <44512305.90207@pobox.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Passing functions to function by reference From: rasmus@lerdorf.com (Rasmus Lerdorf) Brion Vibber wrote: > Rasmus Lerdorf wrote: >>> PHP 5.0 broke this. There was a fatal error on the array_shift that >>> only variables could be passed by reference. There was a good >>> argument for it. So, we started migrating our code. >>> >>> Well, seems this works in 5.1. So, my question is, was it an >>> intentional "fix" or will this break again and we need to continue to >>> watch for this? >> In 5.1 this now throws an E_STRICT instead of a warning. It is still a >> bad idea to pass a tempvar by reference, so yes, you should strive to >> write E_STRICT clean code. > > Stupid question: why is it a bad idea? Well, the original reason was because it caused weird and wonderful memory corruption in PHP 4.3.x, so if your code is ever going to run on that version you really need to not do that. It also tends to be a bug. Most functions that take an argument by reference do so for a reason. There are of course exceptions to this as you have pointed out and in those cases assuming your code will never run under PHP 4.3.x it can be valid. I would still say it is a better idea to something like: func_taking_reference($quiet=some_func()); // throw away ref mod and document the fact that you are intentionally throwing away the reference modification that func_taking_reference is making. That way you avoid the E_STRICT and make it very clear what you are doing. You could make the same argument for using undefined variables. Often that indicates a bug so the E_NOTICE can be really helpful, but other times it just gets in the way. I don't think that means we should do away with the E_NOTICE on that and I also don't think it means you shouldn't try to write E_NOTICE clean code. -Rasmus