|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20583 Variable values inconsistent with assignment statements.
Submitted: 2002-11-22 12:58 UTC Modified: 2003-04-21 09:17 UTC
Avg. Score:4.6 ± 0.7
Reproduced:12 of 13 (92.3%)
Same Version:7 (58.3%)
Same OS:6 (50.0%)
From: jseverson at myersinternet dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4CVS-2002-11-22 (stable) OS: RedHat 7.2
Private report: No CVE-ID:
 [2002-11-22 12:58 UTC] jseverson at myersinternet dot com
I haven't been able to recreate this problem at all in a controlled environment, but I can recreate it consistently where we originally discovered it. 

Here is the snidbit of the function causing the erroneous output:
function do_mail_command($cmd,$server="") {

print "values prior to setting are:<p> server => $server<br>errno => $errno<br>errstr => $errstr<br>whoknows => $whoknows<br>";

if(empty($server)) {
  print "<br>server is empty, so changing values<p>";
  		$server = "this is the first one";
  		$errno = "here is the second one";
  		$errstr = "but they will all be this";
  		$random_variable = "does this work";
	  	print "values after setting:<p> server => $server<br>errno => $errno<br>errstr => $errstr<br>whoknows => $whoknows";

    $fp = fsockopen($server, 5154, $errno, $errstr, 10);

Here is the output of that exact piece of code:

values prior to setting are:
server =>
errno =>
errstr =>
whoknows =>

server is empty, so changing values

values after setting:

server => does this work
errno => does this work
errstr => does this work
whoknows => does this work


There are three main problems I see occurring here.

1. The first print statement prints out a bunch of "random" variables, $server being the only that has previously been given a value. However, as the print statement shows, they ALL have values.

2. The empty($server) check returns true even though its obviously clear that $server is NOT empty.

3. After performing variuos assignment statements within the if block, and printing out the variable values, it's clear that ALL the variables receive the value of the LAST assignment statement made.

We found this bug because when calling fsockopen, the $errno and $errstr variables had values even though they were never assigned any values and it was causing the function to fail when trying to open the socket. This function was working fine prior to our upgrade to the latest version.

Our configure line is:
LoadModule php4_module modules/

We are also heavily using session variables in case that helps to recreate the bug.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-21 17:16 UTC]
Bug #22367 is kind of similar to this bug.

 [2003-03-25 17:40 UTC] jseverson at myersinternet dot com
This bug is related to or the same as the following bugs:

<a href="">21312</a>
<a href="">22367</a>
<a href="">22836</a>
<a href="">22117</a>
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Oct 13 07:01:43 2015 UTC