Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79459 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32430 invoked from network); 6 Dec 2014 14:39:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2014 14:39:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.179 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.179 mail-wi0-f179.google.com Received: from [209.85.212.179] ([209.85.212.179:63505] helo=mail-wi0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/42-14211-01513845 for ; Sat, 06 Dec 2014 09:39:13 -0500 Received: by mail-wi0-f179.google.com with SMTP id ex7so1195499wid.6 for ; Sat, 06 Dec 2014 06:39:08 -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=ULGXrFbTBH19Ti2mTyncrE+52nQ2qQFdHUnNpYlzTBo=; b=NIumeuSsxvmH+9y11aVusb7tUPEYb7B+DO6eHUs7nBAdHKx1pq+Pvc1LxcDw4S17G+ z4yvw+TzycHgEfu1d2jEKDpS1UhdKYAWx27/D1dImhnReU+ON2lPFzGzt9uMRqc+hlQg AnH7PkPBshFHt0SE89mBiTGmitSAHOAUlT1cutSVKxuCikXv23R8Chc8BhEpc+2C+Lsj l+vZ2VFYsv04vW1XOmQ85riSKm7Ks+0oI62wt8bxf8n2kwff2eeeMe+2Z3mj1Q+gw9+l 3NpoXl4K+l1aT3cXP+jAERo+W+rOqzaV+wt53FSGGYqmacQuMHUR7cSwTv7exWT7DBEj 5Feg== X-Received: by 10.195.11.38 with SMTP id ef6mr32117910wjd.68.1417876748476; Sat, 06 Dec 2014 06:39:08 -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 ep9sm2106666wid.3.2014.12.06.06.39.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Dec 2014 06:39:07 -0800 (PST) Message-ID: <548314F4.1090807@gmail.com> Date: Sat, 06 Dec 2014 14:38:44 +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: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Fwd: Re: [PHP-DEV] Re: Only variables can be passed by reference From: rowan.collins@gmail.com (Rowan Collins) On 04/12/2014 23:46, Chris Wright wrote: > Forgot to cc list, see below > > ---------- Forwarded message ---------- > From: "Chris Wright" > Date: 4 Dec 2014 14:09 > Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference > To: "Andrea Faulds" > Cc: > >> On 4 December 2014 at 12:26, Andrea Faulds wrote: >>> >>>> On 4 Dec 2014, at 10:38, Yasuo Ohgaki wrote: >>>> >>>> >>>> Yet another sample code. This cannot be executed on 3v4l.org for > security >>>> reasons. >>>> >>>> >>> $sock = fsockopen('www.php.net', '80'); >>>> var_dump($sock); >>>> >>>> $socks = array($sock); >>>> var_dump(stream_select($socks, $socks, $socks, 1)); >>>> >>>> //var_dump(stream_select(array($sock), array($sock), array($sock), 1)); >>>> //Fatal error: Only variables can be passed by reference in >>>> /home/yohgaki/tmp/ttt.php on line 8 >>>> ?> >>> Using stream_select without real variables like that is weird, what’s > the point? You’ve discarded the read/write/error information, all the > return value tells you is that *something* changed. >> While I'm undecided on this change (leaning towards "no"), there is a > more useful example with stream_select(): >> $socks = array($sock); >> var_dump(stream_select($socks, $socks, NULL, 1)); >> >> It is rare that anything actually uses OOB data in the real world, more > often than not stream_select() is preceded by a line like $e = NULL; >> I could maybe get behind this for specifically permitting literal NULL to > be passed, as is often the convention for out params in C, where passing a > NULL pointer is permitted and handled as "I don't want this data". >> Another example of where this could be useful is stream_socket_client(), > where you want to specify timeout/flags/context but don't care about > errno/errstr, so you could pass literal NULL to these instead of having to > declare a couple of trash variables. >> That said, the use cases above would probably be better served by named > parameters. > Perhaps if a parameter is optional and defaulted to null, a literal null could be allowed even if it would normally be by-ref? This would match the behaviour of type-hinting, e.g. function foo(Bar $bar=null) { ... } foo(null); function foo(&$bar=null) { ... } foo(null); The point being that you could then skip over by-ref parameters in some of the examples above, e.g. allow this: $sock = fsockopen('www.php.net', '80'); $socks = array($sock); stream_select($socks, null, null, 1); Named parameters would make this look prettier, but you'd need to make the parameters optional in the declaration anyway. -- Rowan Collins [IMSoP]