ID: 37761 Updated by: [EMAIL PROTECTED] Reported By: hadrianoliver at hotmail dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Windows XP Service Pack 2 PHP Version: 5CVS-2006-06-09 (snap) New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/language.references.pass.php Previous Comments: ------------------------------------------------------------------------ [2006-06-09 11:19:21] hadrianoliver at hotmail dot com //Correction: _array() function should be: function &_array() { $a = array('a', 'b', 'c'); return $a; } ------------------------------------------------------------------------ [2006-06-09 11:17:19] hadrianoliver at hotmail dot com 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 this bug report at http://bugs.php.net/?id=37761&edit=1