From: hadrianoliver at hotmail dot com
Operating system: Windows XP Service Pack 2
PHP version: 5CVS-2006-06-09 (snap)
PHP Bug Type: Scripting Engine problem
Bug description: Pass by reference function parameter passed as copy
Description:
------------
When passing an argument to a function such as: -
preg_match( string pattern, string subject [, array &matches [, int
flags [, int offset]]] )
using the syntax:
preg_match($pattern, $subject, $array = array())
a copy of the $array is passed to the function, rather than a pointer.
Reproduce code:
---------------
// Without first defining variable
preg_match("/a/", "a", $matches1);
echo count($matches1); // Outputs 1 - OK
// Defining variable before function call
$matches2 = array();
preg_match("/a/", "a", $matches2);
echo count($matches2); // Outputs 1 - OK
// Defining variable within function parameters
preg_match("/a/", "a", $matches3 = array());
echo count($matches3); // Outputs 0 - UNEXPECTED!!
Expected result:
----------------
Expected result: 111
Actual result:
--------------
Observed result: 110
Further toying around, such as by using: -
function _array()
{
$a = array('a', 'b', 'c');
}
instead of array() and
function _preg_match($pattern, $subject, &$matches)
{
if (!$matches)
{
$digits = array();
}
echo "in: " . count($matches) ."<br/>\n";
$result = preg_match($pattern, $subject, $matches);
echo "out: " . count($matches) ."<br/>\n";
return $result;
}
instead of preg_match(), reveal that the array is being passed by copy,
not reference.
--
Edit bug report at http://bugs.php.net/?id=37761&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37761&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=37761&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37761&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37761&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37761&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37761&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37761&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37761&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37761&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37761&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37761&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37761&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37761&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37761&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37761&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37761&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37761&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37761&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37761&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37761&r=mysqlcfg