Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64756 invoked from network); 24 Feb 2015 11:37:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 11:37:51 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.175 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:37245] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/B4-37184-E826CE45 for ; Tue, 24 Feb 2015 06:37:51 -0500 Received: by mail-wi0-f175.google.com with SMTP id r20so24767819wiv.2 for ; Tue, 24 Feb 2015 03:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=hjVPwtbdISOjOQmgEehwJ+nlCE10OTqTKZ0bP8l2KO0=; b=J/RzU8bOk5g5/wUZ7QoCOHL6x34TJmQHmv0MaLT0Xo9fJteVNgDEV3zX/B4oeoG1LN vRS8Zk6/iG/xfojHf6wi44hASTC3zjhvOf53tpx22vSerVCW1Yh2n6X3ffBwDD9qKZJe lImyH4rS16SqppdK2fyAC9LILXIGmYZ0G3kCvwWnFnY86KDy+JuWQuh4IljbCs9S27gS k0kb5gyT7GfP+9xJ0MgaQ8n+fkhuEh5HnpZoQ5oowZKlKHhOVhF9gDIhUeNznhxKhHjF 6KSUsrty2VuQeK4HkLylAhtACU59+DiYw82jOeIPXJ3kF+7liWtJsA/aMfuaxMbDUX4w 74xw== MIME-Version: 1.0 X-Received: by 10.194.2.75 with SMTP id 11mr31368824wjs.78.1424777867700; Tue, 24 Feb 2015 03:37:47 -0800 (PST) Received: by 10.27.10.168 with HTTP; Tue, 24 Feb 2015 03:37:47 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 12:37:47 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=047d7b3a834cb03126050fd3f206 Subject: Re: Mark some functions with PREFER_REF From: nikita.ppv@gmail.com (Nikita Popov) --047d7b3a834cb03126050fd3f206 Content-Type: text/plain; charset=UTF-8 On Mon, Feb 23, 2015 at 10:36 PM, Nikita Popov wrote: > Hi internals! > > With regard to my E_STRICT RFC [1] Yasuo and another off-the-record mail > expressed a concern about the "Only variables should be passed by > reference" strict standards warning. > > This notices makes sense in a lot of places, e.g. > > array_push(getArray(), 1, 2, 3); > > is totally pointless code if getArray() doesn't return a reference. > array_push will just modify a temporary array in this case. > > However other usages like > > $top = array_pop(getArray()); > > are less clear: array_pop() both has a side-effect (removing the top > element of an array) and a meaningful return value (the top element of the > array). As PHP does not have a dedicated function for getting the > first/last element of an array, many people use code like this (which > currently throws E_STRICT) instead. > > I'd like to mark a few such functions with PREFER_REF (i.e. allow passing > both references and values). In particular array_pop() and array_shift(). > > Does anybody have a problem with us doing this? Are there other functions > which should use PREFER_REF? > > The motivation behind this is to make sure we only throw this notice in > cases where the code is actually buggy/nonsensical instead of just making > people ignore it altogether. > A few people have pointed out OTR that the same applies to reset() and end(). Both can be used to get the first/last element (and change the IAP as a side effect). So I'd add PREFER_REF to those as well. (Interestingly key() and current() already use PREFR_REF even though they don't modify the array at all, probably this is a performance optimization.) Nikita --047d7b3a834cb03126050fd3f206--