Hi Andrea, Stas and all

On Thu, Dec 4, 2014 at 9:26 PM, Andrea Faulds <a...@ajf.me> wrote:

> > <?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’s the
> point? You’ve discarded the read/write/error information, all the return
> value tells you is that *something* changed.


There are 2 points.
It does not have to be module functions. User may define function which has
similar to stream_select().

int stream_select ( array &$read , array &$write , array &$except , int
$tv_sec [, int $tv_usec = 0 ] )

This kind of signature requires $tv_sec. If $write and $except can
null(NULL) or empty array(array() or []), but it does not allowed.

Even when there is parameter to pass, user has to create variable always.

select_select([$a], [$b], [$c], 10);

fails with E_ERROR, while

$x = [$a];
$y = [$b];
$z = [$c];
stream_select($x, $y, $z, 10);

works, but It does not look nice.

Stas points out "these are constant".
It is a kind of constant since array(1,2,3) is array literal and value
never changes.
I'm not sure how literals are handles in Zend engine, but it may use the
value as
referenced parameter.

array_splice(array(1,2,3,4), 2);

Code like this is useful to get certain part of config, etc.
Nobody writes code like above directly. If function returns literal and
passed as
referenced argument, then PHP raises error.

Please take a look at this code

http://3v4l.org/qUDOv

Raising errors for this kind of code is not good. IMHO.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to