From:             public at hverdag dot dk
Operating system: Windows 2000
PHP version:      4.3.1
PHP Bug Type:     Variables related
Bug description:  Arguments passed to function changes!

I have one function (see it below) where I pass 2 arguments. But sometimes
(yes, only sometimes!) when inside the function myfield has the same value
as myvalue instead of it's own value. In other words, it simply changes
the values of the arguments!

I have a long script where I at one point have a line like this several
times to build up my SQL statement, calling this function:

  $enterSQL .= field_to_sql('category', 'autovalue');

But when I check the value of these two arguments inside the function both
arguments have the value 'autovalue'!

This happens inside my long script and it can happen usually two times
(meaning: after a page reload) but the third time (second reload) the
problem is gone and script executes as expected! And if I try to call this
function from another simple page the problem never occurs.

I'm using sessions but I cannot see how that should affect any of this
(meaning, page reload should not affect anything).

Here is the function (which is located in an included file in the above
mentioned script):

  function field_to_sql($myfield, $myvalue) {
        echo "<br>+". $myfield . "+". $myvalue ."+";
        #this outputs wrong value for the myfield variable!
        if ($myvalue == 'autovalue') {
                $myvalue_var_name = 'value_' . $myfield;
                global $$myvalue_var_name;
                if (!isset($$myvalue_var_name)) {                       echo 'Warning, 
variable is not
set';
                }
                $myvalue = $$myvalue_var_name;
        }
        $myvalue = str_replace("'", "\'", $myvalue);
        if ($myvalue == '') {
                return "`$myfield` = null, ";
        } else {
                return "`$myfield` = '$myvalue', ";
        }
  }

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

Reply via email to