|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49319 Global variable is valid in the beginning of .php, which is invalid at the end.
Submitted: 2009-08-21 09:59 UTC Modified: 2009-08-29 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: yippaolo at yahoo dot com Assigned:
Status: No Feedback Package: Variables related
PHP Version: 5.2.10 OS: *
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.
Block user comment
Status: Assign to:
Bug Type:
From: yippaolo at yahoo dot com
New email:
PHP Version: OS:


 [2009-08-21 09:59 UTC] yippaolo at yahoo dot com
Apache version:2.0.63; PHP version 5.2.10 (.zip); IE 6.0 SP3
I defined a global variable in the beginning of the .php file. It is valid at the beginning of the file, while it becomes invalid at the end of the file. There is no function defined in this .php file.
For the details pls see reproduce code.

Reproduce code:
All the places this variable is defined or refered are as follows.
line 20:  $isloc=$_GET["l"];//Define. It works!
line 31:  switch($isloc){...}
line 37:  if($isloc!="")
line 109:  for($a=1;$a<=$pages;$a++)
line 110: {//for
line 111:  if($a!=$gpage)$cmmt1.='<a href=***.php?l='.$isloc.'&id='...'</a>&nbsp;';////It works!
line 112:  else ...			
line 113:  }//for  }//if  
line 114:  if($isloc!="")echo $isloc;///It becomes null!
line 115:  else echo '$isloc is null';

Expected result:
shows the value of $isloc

Actual result:
'$isloc is null'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-21 10:01 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2009-08-21 10:10 UTC] yippaolo at yahoo dot com
I just tried the test case. The variable works all the time. Still don't know the reason for failure in the big file mentioned before.

switch($isloc){ case '1':;}
	else {}		
if($isloc!=""){echo $isloc;}
else {echo '$isloc is null';}
 [2009-08-21 10:15 UTC]
The variable is certainly being set somewhere in the big script.

I set this bug back to feedback, pls reopen it only when you have a way to reproduce your problem, or tell us if you can't (will then bogus this report).
 [2009-08-29 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 08 13:03:41 2021 UTC