#36191 [NEW]: statement as function parameter gets evaluated after calling the function

From: Date: Sat, 28 Jan 2006 13:02:00 +0000
Subject: #36191 [NEW]: statement as function parameter gets evaluated after calling the function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-92578@lists.php.net to get a copy of this message
From:             mail dot spam at gmx dot net
Operating system: Windows
PHP version:      5.1.2
PHP Bug Type:     *General Issues
Bug description:  statement as function parameter gets evaluated after calling the function

Description:
------------
if you use a statement as actual parameter for a function (parameter is
called by reference) the statement get's executed after calling the
function thus overwriting the function's work

Reproduce code:
---------------
function test_array(&$test) {
	$test[] = 2;
}

echo '<pre>';

test_array($test_1);

test_array($test_2 = array(1));

$test_3 = array(1);
test_array($test_3);

print_r($test_1);
print_r($test_2);
print_r($test_3);

echo 'PHP-Version: '.phpversion();
echo '</pre>';

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

Actual result:
--------------
output for version 4.3.11
Array
(
    [0] => 2
)
Array
(
    [0] => 1
    [1] => 2
)
Array
(
    [0] => 1
    [1] => 2
)


output for version 5.1.2
Array
(
    [0] => 2
)
Array
(
    [0] => 1
)
Array
(
    [0] => 1
    [1] => 2
)

-- 
Edit bug report at http://bugs.php.net/?id=36191&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36191&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36191&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36191&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36191&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=36191&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36191&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36191&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36191&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36191&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36191&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=36191&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=36191&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36191&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36191&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36191&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36191&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36191&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36191&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36191&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36191&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#92578) next »