#27395 [NEW]: arrays cannot be passed by value

From: Date: Wed, 25 Feb 2004 17:02:03 +0000
Subject: #27395 [NEW]: arrays cannot be passed by value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-55542@lists.php.net to get a copy of this message
From:             jamesn at tocquigny dot com
Operating system: redhat linux
PHP version:      4.3.4
PHP Bug Type:     Scripting Engine problem
Bug description:  arrays cannot be passed by value

Description:
------------
There appears to be a problem with php that doesn't allow arrays to be
passed by value.  The fix appears to be something similar to:
http://bugs.php.net/bug.php?id=6417
if (PZVAL_IS_REF(*p))
{
   SEPARATE_ZVAL(p);
} else {
   zval_add_ref(p);
}

It would appear that that logic is missing in one place or another.  I
could not track it down myself.  Code similar to this appears to be
copy/pasted in various places.

Reproduce code:
---------------
$array = array(1);

// This line makes the call to theFunction() act as if passed by ref.?
$reference =& $array[0];

echo $array[0], '<br>';
theFunction($array);

echo $array[0], '<br>';

function theFunction($array) {
    $array[0] = 2;
}

Expected result:
----------------
you should get 1 and 1

Actual result:
--------------
instead you get 1 and 2!

-- 
Edit bug report at http://bugs.php.net/?id=27395&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27395&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27395&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27395&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27395&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27395&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27395&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27395&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27395&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27395&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27395&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27395&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27395&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27395&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27395&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27395&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27395&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27395&r=float


Thread (10 messages)

« previous php.bugs (#55542) next »