Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79458 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30777 invoked from network); 6 Dec 2014 14:29:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2014 14:29:49 -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.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wg0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:34876] helo=mail-wg0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/F1-14211-CD213845 for ; Sat, 06 Dec 2014 09:29:49 -0500 Received: by mail-wg0-f43.google.com with SMTP id l18so3008188wgh.30 for ; Sat, 06 Dec 2014 06:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=ln/VJYkqhL0fFMd4E7xQUIYoBdgHXeJVoWBJe8W6NjE=; b=hgO1Jvmtv/n8Jl1cDveapsYCuvewkScVT3FM4SbGBCIUwYjIfRTNgQLkm17VcaWAeh ZJAUHI162sBL3cN6q8EWmnq4McwCB8yDO/NfXzPPDWbQCqX9xAA+d5enWFTroOuElWFn WK7YQBo2RmwpHYFVPJsHraVUrrbuHuAzsJe6zqXmhNPLXV78dV4Q9ZuOAs8bbIkLgXN9 W5Lkv20oxSo7IBtqFGuuc4K9Q1Wr2QWar2M3bj7+D8fMIcUR8hkffXsdvRoBldSvCsET EOPgipr7u9yzZTYPNZQZmjG9R1lxQyuATNuxtDBdym0gUhdqmPVvnMNBNgNS1C/23Ntu h8pQ== X-Received: by 10.180.21.140 with SMTP id v12mr11849753wie.44.1417876185053; Sat, 06 Dec 2014 06:29:45 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id eu8sm2049064wib.21.2014.12.06.06.29.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Dec 2014 06:29:44 -0800 (PST) Message-ID: <548312C1.6020800@gmail.com> Date: Sat, 06 Dec 2014 14:29:21 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: "internals@lists.php.net" References: <2D560BB1-318F-461F-96CD-BE25C346E14F@gmail.com> <5482E1C1.9030908@gmx.de> In-Reply-To: <5482E1C1.9030908@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference From: rowan.collins@gmail.com (Rowan Collins) On 06/12/2014 11:00, Christoph Becker wrote: > Yasuo Ohgaki wrote: > >> In languages, there are literal, constant and variable. Return value is >> variable. >> 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? >> Are there any other languages behave like PHP? > IMHO, the first snippet is confusing (the second as well, if $v is not > used in the following code). Actually, you don't want to pop the top of > the stack, but you want to simply get it without altering the stack at > all. Therefore it seems reasonable to use a function called array_top() > (or so) which takes its argument by value. I think this hits the nail on the head: most times when you're trying to pass a literal or return to a by-ref parameter, it's because the function you're using isn't actually the right fit for what you're trying to do - either because it's badly designed (arguably the case with stream_select()) or because you're using it for a purpose it wasn't intended for (e.g. array_pop() if you're not going to use the rest of the stack). For user-defined functions, one reaction to the E_STRICT notice might be to realise that you don't actually need a by-ref parameter there anyway, so you can remove the & in the declaration, and everything's fine. For internal functions, it may mean that we're lacking something useful (e.g. accessing first and last elements of arrays without side-effects). -- Rowan Collins [IMSoP]