Edit report at https://bugs.php.net/bug.php?id=63087&edit=1

 ID:                 63087
 Comment by:         ni...@php.net
 Reported by:        charlie at charliesomerville dot com
 Summary:            Passing a reference to a function does not work when
                     parentheses are used
 Status:             Feedback
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        master-Git-2012-09-14 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

@charlie: You can find a detailed description of why this happens here: 
http://stackoverflow.com/questions/6726589/parentheses-altering-semantics-of-function-call-result/6732876#6732876

This is once again an issue caused by the AST-less compilation process. 
(https://wiki.php.net/rfc/ast_based_parsing_compilation_process)


Previous Comments:
------------------------------------------------------------------------
[2012-09-14 09:56:49] larue...@php.net

wrong status.

------------------------------------------------------------------------
[2012-09-14 09:55:23] larue...@php.net

it will be appreciated, thanks

------------------------------------------------------------------------
[2012-09-14 09:52:14] charlie at charliesomerville dot com

If you leave the ticket open, I might try my hand at fixing this.

------------------------------------------------------------------------
[2012-09-14 09:45:55] larue...@php.net

yes, this is a knew issue, the similar thing will also happen while you use '@';

you will get a STRICT WARNING about this. right?

I'd like mark this as wont'fix, it's a compiler issue, fix this is expensive

------------------------------------------------------------------------
[2012-09-14 07:01:04] charlie at charliesomerville dot com

Description:
------------
To be specific, this only occurs when passing a reference returned by a 
function 
into another function that takes a reference.

This behaves as expected with a variable instead of a function call, so I 
believe 
this is a bug.

Test script:
---------------
<?php

function &return_a() {
    global $a;
    return $a;
}

$a = [1,2,3];
array_shift(return_a());
print_r($a);

$a = [1,2,3];
array_shift((return_a()));
print_r($a);

Expected result:
----------------
Array
(
    [0] => 2
    [1] => 3
)
Array
(
    [0] => 2
    [1] => 3
)

Actual result:
--------------
Array
(
    [0] => 2
    [1] => 3
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63087&edit=1

Reply via email to