php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22575 Arguments passed to function changes!
Submitted: 2003-03-06 14:48 UTC Modified: 2003-03-12 17:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: public at hverdag dot dk Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.1 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: public at hverdag dot dk
New email:
PHP Version: OS:

 

 [2003-03-06 14:48 UTC] public at hverdag dot dk
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', ";
	}
  }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-06 22:05 UTC] sniper@php.net
It's most likely caused by sessions.
Try adding 'error_reporting(E_ALL);' as first line
in the script and see what errors you get.

 [2003-03-09 16:28 UTC] public at hverdag dot dk
Enabling all error/warnings/notices only gives some undefined variables and indexes, and it's the same notices whether the page executes correct or not. So I cannot see any problem there.

Talking about a session problem, how would that be?
 [2003-03-09 17:49 UTC] sniper@php.net
Please provide a full script (short!) that clearly demonstrates the problem and can be simply cut'n'pasted from this report.

 [2003-03-12 10:35 UTC] public at hverdag dot dk
That's a problem since it's a quite complex page divided into sections where you have to enter and submit 3-4 times before you come to the section where the error occurs.

And when I just take those function calls out and put in a seperate page the problem never occurs!

I call the function several times like this:

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

Then on the very first line within the function I echo the two values out to the browser and suddenly the first argument has the value 'autovalue' instead of 'category'! 

Couldn't that seem like a memory problem since it doesn't remember the values correctly? I don't understand how it can be session related - espacially when the values passed to the function are static - not variables!
 [2003-03-12 17:20 UTC] sniper@php.net
As long as you can't provide any proof, we have to assume
it's not PHP bug but something you're doing wrong. (I'm 99% sure about this). Try setting register_globals=off for a change..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC