Re: Fwd: Re: [PHP-DEV] Re: Only variables can be passed by reference
| From: | Rowan Collins | Date: | Sat, 06 Dec 2014 14:38:44 +0000 |
| Subject: | Re: Fwd: Re: [PHP-DEV] Re: Only variables can be passed by reference | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79459@lists.php.net to get a copy of this message | ||
On 04/12/2014 23:46, Chris Wright wrote:
Forgot to cc list, see below ---------- Forwarded message ---------- From: "Chris Wright" <cw@daverandom.com> Date: 4 Dec 2014 14:09 Subject: Re: [PHP-DEV] Re: Only variables can be passed by reference To: "Andrea Faulds" <ajf@ajf.me> Cc: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]On 4 December 2014 at 12:26, Andrea Faulds <ajf@ajf.me> wrote:securityOn 4 Dec 2014, at 10:38, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: Yet another sample code. This cannot be executed on 3v4l.org forthe point? You’ve discarded the read/write/error information, all the return value tells you is that *something* changed.reasons. <?php $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’sWhile I'm undecided on this change (leaning towards "no"), there is amore 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, moreoften than not stream_select() is preceded by a line like $e = NULL;I could maybe get behind this for specifically permitting literal NULL tobe 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 namedparameters.