Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83663 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84729 invoked from network); 24 Feb 2015 13:55:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 13:55:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:43632] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/21-10521-AC28CE45 for ; Tue, 24 Feb 2015 08:55:24 -0500 Received: by mail-vc0-f179.google.com with SMTP id hy4so10020477vcb.10 for ; Tue, 24 Feb 2015 05:55:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=uR83J41dEnYKaKZPMkm5a5Eq99o5p+1+2YVnl1GtpDI=; b=mVoHkysrt7yEQLX5OQRGtKWIU2QGAPGXVLJKAcH+XXeMo2mKMADb5qcTeWpIntAKUJ 7eD683Hc3J3dF9yRxEmBdx3ELdoyF2ogYC+Bt7EUuH3fCnXGvf2417n+latoPhMG2Z7c f7eWywquTiYHhN9M3k1KvDKhXx5sudQ2vTSauQisvQZGrszte14qHkUqFpUBu4V8Ghbh tu4PNmeCKjwRBdyiV04523/x/8Q+euBZzb7kWcmqLMB98t84U8vjn15JtSIz6U8f87RN vVY7ne0DZrZQrXzV3b4CdY+siAq0Tlyf8bp1DHErNwn2KTMlMfjDY7D22ThCFt5jSZNl mAtQ== X-Gm-Message-State: ALoCoQk3gUCQi20TTey7Rbk8rXowjnAIpFAXPDHbyBIUc4MKatyUw7eE8vckyZJyScz+eQDovCwzjTmkLFBzUZOkGiqnSjBY9j37M0kIELVJEQoGT2FNAUaCu4aeXUGyrJBtDL/ALMy8YF9AQdSz+0sOgbBJpe5pYg== MIME-Version: 1.0 X-Received: by 10.52.25.11 with SMTP id y11mr15398389vdf.51.1424786116744; Tue, 24 Feb 2015 05:55:16 -0800 (PST) Received: by 10.52.113.231 with HTTP; Tue, 24 Feb 2015 05:55:16 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 17:55:16 +0400 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1133e5f25ead43050fd5de5a Subject: Re: [PHP-DEV] Re: Mark some functions with PREFER_REF From: dmitry@zend.com (Dmitry Stogov) --001a1133e5f25ead43050fd5de5a Content-Type: text/plain; charset=UTF-8 On Tue, Feb 24, 2015 at 2:37 PM, Nikita Popov wrote: > 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.) > key() and current() shouldn't use it. It was an optimization from PHP5 time that makes for PHP-7 more harm than benefit. According to array_pop(), array_shift(), reset() and end(), it's not a problem to avoid this warning. But note that such usage of these functions may be really inefficient, because they may need to duplicate the passed array first. Thanks. Dmitry. > > Nikita > --001a1133e5f25ead43050fd5de5a--