Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79439 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25813 invoked from network); 5 Dec 2014 09:12:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Dec 2014 09:12:48 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wg0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:37541] helo=mail-wg0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/F6-61462-D0771845 for ; Fri, 05 Dec 2014 04:12:46 -0500 Received: by mail-wg0-f53.google.com with SMTP id l18so352869wgh.12 for ; Fri, 05 Dec 2014 01:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=BSkirObRUKXo/a2O1Lcy0ey7aQm1EJrBnkgBm81wEAA=; b=aTtkUSdxVGFwXQNs73vwY4VOGF8SFq9v/ZlccbT3W5PKZ7W9lOzOMoTZn0ZJac47Pr a+x8tVhUKXhhjGBCEJp4hhzGLdh15qCAZU5qE1sjJFVpBZraa36lGPb57mHYe8JZ9zA0 JzSdyBgGVLsIYFMtr+XW1ET5xYyodtIOQy4/2VjV4Z4QFMEVrCNzEC8lutU2KKf+9lHL myS7WR/MY8X/QkmNnAMAobeCVLhNgW1ck96sZq9TcoqRALi3G54wXLfJIZh2uBVjryTB DCx8xDM3FyaHHbkjT/nrYg2HIu6WEpKOrR5grx8SgyrRMfvV8Y/fCYVbZ9V8zeOmrmb5 91Qg== X-Received: by 10.180.83.228 with SMTP id t4mr2658494wiy.28.1417770762460; Fri, 05 Dec 2014 01:12:42 -0800 (PST) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id dg7sm1417257wib.24.2014.12.05.01.12.41 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Dec 2014 01:12:41 -0800 (PST) User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Fri, 05 Dec 2014 09:12:37 +0000 To: "internals@lists.php.net" Message-ID: <2D560BB1-318F-461F-96CD-BE25C346E14F@gmail.com> Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference From: rowan.collins@gmail.com (Rowan Collins) On 5 December 2014 01:07:03 GMT, Yasuo Ohgaki wrote: >Hi all, > >On Thu, Dec 4, 2014 at 5:28 PM, Yasuo Ohgaki >wrote: > >> I think we can get rid of this error now when literal is returned. >> The reason we have E_STRICT error is that legacy PHP didn't >> support this, I suppose. >> >> http://3v4l.org/8fISj >> >> Is it possible to allow literal as referenced parameter for PHP7? >> It's better to remove needless restrictions where it is possible. >> HHVM seems already support this. >> >> http://3v4l.org/t79rF >> >> Any comments? >> > >It may be better to focus on return value from functions/methods. > >There are cases that return values are better to be treated as usual >variables. For example, > >function f1(&$v) {} >function f2() {$a = array(1,2,3); return $a; } > >f1(f2()); >?> > >http://3v4l.org/2prWX > >E_STRICT error here is too much. IMHO. >I think this kind of code should be allowed without errors rather than >forcing users to save return value to variable. e.g. > >$v = f2(); >f1($v); The author of function f1() presumably designed it to apply some change to $v, rather than executing only for its side effects and return value. If the caller wants to ignore this design, they can, but they are not using the function as it was designed. If they pass a function return straight into it, they have no way of capturing the change to $v which the author intended them to see. E_STRICT seems like the perfect output for that: "what you're doing will work, but it's probably not the best idea, and there's an easy tweak you might want to consider". You might want some way of saying "no, I really meant to do that" (more elegantly than the @ operator), but E_STRICT is full of hints like this that border on coding style, so if you don't like that, just mask it out of error_reporting. That's my 2 pence, anyway. -- Rowan Collins [IMSoP]