Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79462 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57902 invoked from network); 6 Dec 2014 22:38:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2014 22:38:37 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.245 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.245 imap11-3.ox.privateemail.com Received: from [198.187.29.245] ([198.187.29.245:35273] helo=imap11-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/C0-52283-C6583845 for ; Sat, 06 Dec 2014 17:38:36 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 58EBB8800DB; Sat, 6 Dec 2014 17:38:33 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3yOiWAOpnXUg; Sat, 6 Dec 2014 17:38:33 -0500 (EST) Received: from [10.0.110.77] (border-converged.hackerdeen.org [89.104.225.218]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 7A0728800E2; Sat, 6 Dec 2014 17:38:31 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Sat, 6 Dec 2014 22:38:30 +0000 Cc: Rowan Collins , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: References: <2D560BB1-318F-461F-96CD-BE25C346E14F@gmail.com> <548311E6.9010406@gmail.com> To: Yasuo Ohgaki X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference From: ajf@ajf.me (Andrea Faulds) Hi! > On 6 Dec 2014, at 22:25, Yasuo Ohgaki wrote: >=20 > 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. The C world already has terminology for this: * lvalues - values on the left-hand side of an assignment, they can be = assigned to Examples in PHP include: * $foo * $foo->bar * $foo->bar[0] * rvalues - a superset of lvalues, these are values that can be on the = right-hand side of an assignment Examples include: * All the lvalues above * 3 * 2 + 3 * foobar() * $foo + $bar * (int)$foo In C, you (usually) can only get pointers to lvalues, as only lvalues = can be written to. In PHP, it would make sense only to be able to = reference lvalues, as only lvalues can be written to. In fact, we = (almost?) always treat references as if they were assignments, hence why = you can reference non-existent variables, because you can assign to = non-existent variables. AFAIK this may be because referencing a value = inherently modifies it (in PHP 5 and earlier, it sets the if_ref flag, = while in PHP 7 it changes it to an IS_REFERENCE type). Even if = referencing a value didn=E2=80=99t modify it, it allows you to do so = later. Doing something like &(2+3) makes no sense as (2 + 3) isn=E2=80=99t a = variable, it=E2=80=99s a temporary rvalue that is only used once. As others have said, there is no use-case for allowing assignments to or = references to rvalues, it=E2=80=99s completely nonsensical. What would = make sense is adding things like array_top() or array_bottom(), and = perhaps allowing NULL rvalues to be passed to by-reference parameters = with defaults. Thanks! -- Andrea Faulds http://ajf.me/