Bug #79218 [Nab]: inconsistent behavior since call time pass by reference was removed
| From: | skullnobrains at gmail dot com | Date: | Wed, 05 Feb 2020 11:45:00 +0000 |
| Subject: | Bug #79218 [Nab]: inconsistent behavior since call time pass by reference was removed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225374@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79218&edit=1
ID: 79218
User updated by: skullnobrains at gmail dot com
Reported by: skullnobrains at gmail dot com
Summary: inconsistent behavior since call time pass by
reference was removed
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: linux and probably all
PHP Version: 7.3.14
Block user comment: N
Private report: N
New Comment:
IS_A_BUG
Previous Comments:
------------------------------------------------------------------------
[2020-02-05 11:43:40] skullnobrains at gmail dot com
noted.
thanks for your answer. i get this syntax has become wrong.
you may note that the &$R=array(...) idiom used to work as one may think intuitively : affect
array to the $R variable and pass a reference to $R to the func.
so that's a side effect of loosing call time pass by reference which used to make the pass by
value and pass by reference syntaxes consistent.
but then since passing a value is forbidden and otherwise produces a fatal compile time error, it
definitely also SHOULD be detected by the parser at compile time and produce the same behavior.
i know this is not the place, but +1 vote for reverting that very useful feature that made all those
behaviors explicit and allowed the developer to knowingly use either values or references depending
on use cases. this also allowed to extend functions easily without breaking existing code.
------------------------------------------------------------------------
[2020-02-04 20:42:50] a at b dot c dot de
Because in
$num=stream_select($R=array(),$W=array($sock),$O=array(),1)
you're not passing variables to stream_select, you're passing assignment expressions,
which are not variables. (If they were variables, you'd expect to be able to assign values to
them: ($R = array()) = 17; would assign 17 to the variable "$R = array()").
More accurately, you're passing the values that those assignment expressions evaluate to (which
are arrays, not variables); as it happens you're also assigning those same values to some
variables, but that's a side-effect of the evaluation.
------------------------------------------------------------------------
[2020-02-04 13:28:21] skullnobrains at gmail dot com
my bad, the array is not modified.
still the behavior is very unclear and totally inconsistent between a simple runtime notification
and a non working code and a fatal error at compile time if those are actually identical case.
------------------------------------------------------------------------
[2020-02-04 13:25:09] nikic@php.net
I don't see any array being modified in your example. $W is initialized to [$sock] and stays
that way -- the fact that this matches what the function would set it to is coincidental.
------------------------------------------------------------------------
[2020-02-04 13:19:52] skullnobrains at gmail dot com
it does : the code works and the array is modified by stream_select() as demonstrated.
if stream_select is able to modify a non-reference, maybe this is a different bug.
either it should not work at all, or there should be no notification.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79218
--
Edit this bug report at https://bugs.php.net/bug.php?id=79218&edit=1