php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63087 Passing a reference to a function does not work when parentheses are used
Submitted: 2012-09-14 07:01 UTC Modified: 2013-02-18 00:36 UTC
From: charlie at charliesomerville dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: master-Git-2012-09-14 (Git) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: charlie at charliesomerville dot com
New email:
PHP Version: OS:

 

 [2012-09-14 07:01 UTC] 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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-14 09:45 UTC] laruence@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 09:52 UTC] charlie at charliesomerville dot com
If you leave the ticket open, I might try my hand at fixing this.
 [2012-09-14 09:55 UTC] laruence@php.net
it will be appreciated, thanks
 [2012-09-14 09:55 UTC] laruence@php.net
-Status: Open +Status: Analyzed
 [2012-09-14 09:56 UTC] laruence@php.net
wrong status.
 [2012-09-14 09:56 UTC] laruence@php.net
-Status: Analyzed +Status: Feedback
 [2012-09-14 13:31 UTC] nikic@php.net
@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)
 [2013-02-18 00:36 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC