Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79460 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54827 invoked from network); 6 Dec 2014 22:26:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2014 22:26:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.169 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.213.169 mail-ig0-f169.google.com Received: from [209.85.213.169] ([209.85.213.169:51974] helo=mail-ig0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/10-52283-2A283845 for ; Sat, 06 Dec 2014 17:26:43 -0500 Received: by mail-ig0-f169.google.com with SMTP id hl2so2511948igb.0 for ; Sat, 06 Dec 2014 14:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=lG8zYSNHBDfWGBOoRCg4lZpRdKWYJXpLzT3QaJRwhgM=; b=coZ3UnLk4GgzdThjsJPLbgEmiF23/oh+OCdCTLj0ObE/0yvDsFBkVL1Mdu9C7Dlvl8 OZ2XpLaBOWC6O7vB15ZEd7L4O1wGb7MnlPQmB0dLpzw1dRbC08yDrRBnkQ51wL9s1TEp TKGvGyxz80Hog/DZqVrV+a2L8MeURwWcsuaWRZNp3vcEBfuo8Dv8pRs+kz6qRe1ZZ2JB BKmENuK08DyglUadAuvmxVG8e6mmteTRA/UVuBR/CC0lPUtxJC7H78zCVgA65ngCilAr fh1QnvITAMhmSMjocsJ4AUVkrzvqXLYnLXrCUGgZGMdttXJ2SPwkNhfkoHSB6/anjLdE Z7BQ== X-Received: by 10.42.203.199 with SMTP id fj7mr21167979icb.60.1417904790992; Sat, 06 Dec 2014 14:26:30 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.107.164.217 with HTTP; Sat, 6 Dec 2014 14:25:50 -0800 (PST) In-Reply-To: <548311E6.9010406@gmail.com> References: <2D560BB1-318F-461F-96CD-BE25C346E14F@gmail.com> <548311E6.9010406@gmail.com> Date: Sun, 7 Dec 2014 07:25:50 +0900 X-Google-Sender-Auth: WQ8u32VYzQ9YIlnYnomAI7i6T6M Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=485b397dd129647eb8050993af2a Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference From: yohgaki@ohgaki.net (Yasuo Ohgaki) --485b397dd129647eb8050993af2a Content-Type: text/plain; charset=UTF-8 Hi Rowan, On Sat, Dec 6, 2014 at 11:25 PM, Rowan Collins wrote: > On 06/12/2014 03:03, Yasuo Ohgaki wrote: > >> Hi Rowan, >> >> On Fri, Dec 5, 2014 at 6:12 PM, Rowan Collins > > wrote: >> >> 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. >> >> >> The value supplied to f1() is return value. >> In languages, there are literal, constant and variable. Return value is >> variable. >> > > No, a return value is a value - it is the result of some computation which > has not yet been assigned to a variable. This is perhaps more obvious with > an operator: "1 + 2" is not a variable, it is the value 3; internally, a > temporary variable is probably used to hold that value, but that temporary > variable is never accessible to the programmer. If you have function > add($a, $b) { return $a + $b; }, then add(1,2) is still not a variable in > any meaningful sense. Value is vague term. I would like to use "expression". Expression is anything that has value. Variables/constants are values that have actual storage. Literals are values that may not have actual storage. Joe pointed out PHP treats temporary variable differently. I suppose temporary variable is created for values not used as usual variable. e.g. Function return value. It may be the thing we need to reconsider. Temporary variable is an variable after all. It may be used in context that is changed then discarded. Even if we raise errors for temporary variables, it's better to raise _the_same_error_ where is it allowed. http://3v4l.org/9LdkK#v551 I understand that return by ref and returning literal/constant is contradictional, yet it seems too much care for developers. Developer may simply return value that indicates some error in return by ref function should be allowed w/o error. IMHO. > It's better to keep basic rule. IMHO. >> >> $top = array_pop(f2()); >> >> is better than >> >> $v = f2(); >> $top = array_pop($v); >> >> Is there anyone who likes latter? >> > > array_pop() is a stack-manipulation function, so the latter is the correct > use, with $v going on to be used as the rest of the stack. If you're using > it for something other than stack manipulation, neither is correct, because > it's the wrong choice of function. User may use array_slice() for it, but array_pop() is intuitive what it does and works perfectly except unneeded error. Therefore, user surprises what is the "Only variable references should be ..." means. Anyway, I wrote a blog about this spec many years ago and the entry is accessed constantly even today. I suppose PHP7 will have more intuitive/flexible parsing for complex expressions(e.g. f()[2]->method(), etc, isn't it?), then this spec may confuse more users. We don't need unwanted side effects, therefore this change should be done carefully. I wouldn't argue with this. If removing "Only variable references should be ..." error is feasible, I would like to propose this change. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --485b397dd129647eb8050993af2a--