php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22288 Local vars and function parameters not accessible!
Submitted: 2003-02-18 23:26 UTC Modified: 2003-02-23 03:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: andre dot goncalves at martelozero dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.1-dev OS: Linux
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: andre dot goncalves at martelozero dot com
New email:
PHP Version: OS:

 

 [2003-02-18 23:26 UTC] andre dot goncalves at martelozero dot com
Hi! this is really a spooky situation!  

A. problem with a class only happening in one site (other implementations use same class and always worked fine).

B. It only happens the first time I hit the site. 

C. press F5, or re-enter address, and the problem is gone. 

D. restarting browser, causes the problem again. 

E. problem is: 

The 2nd time I call a method on a certain object, 
neither the method parameters, neither the global vars are 
acessible, only the pre-declared class members are there.

Remember, i have made a call to this method in the same script exexcutation, some 20 lines before.

F. Even more spooky, some vars tend to echo values (wrong 
values) but var_dump shows NULL for the same var, 
right from the next line of code!!! 

G. Check below example: 

output 1, 3 and 4 show vardump of function parameters NULL 

ouput 2 shows that local var $_query (the function's parameter $_query) receives the return value of the previous function foofunction() call

output 3 shows that variable is in fact NULL 

output 5 shows that local var is not accessible 

output 6 shows that global var is accessible 

output 7 and 8 shows class members ok 

output 9 and 10 shows assigning local vars impossible!!!! 

H. Don't belive me? TEST IT: 

http://66.220.28.17/zero/index.php 


Looks like assignment of variables is totally messed up (currupt?) 

The script is like dead: I also tried unseting the global 
instance of $mydbclass and recreating it, but I get NULL 
if I vardump the new instance!!! 

Please help me on this one! 


//:: CODE EXTRACT FOLLOWS 

//:: test function 
function foofunction($_bla) { 
return "YOUR BLAH: ".$_bla; 
} 

$fooglobal= "fooglobal"; 

// function call 
$mydbclass->query("select id from user"); 

//class definition 
class mydbclass { 

var $version = 1.0 

function mydbclass() { 
$this->connect(); } 

// more class methods ... 

function query($_query = "foo", $_fooparam = "bar") { 
global $fooglobal; 
global $queryix; 

$queryix++; 
$foolocal = "foolocal"; 
$this->foonewmember = "foonewmember"; 

echo "($queryix) _query="; 
var_dump($_query);echo BR; 
//:: 1 outputs: (2) _query=NULL 

if (!($this->tmp = mysql_query($_query))) { ; 

$this->tmp2 = $this->bla("select id from zero_user"); 

echo "_query echo="; 
echo($_query); 
//::2 outputs: _query echo=YOUR BLAH: bla bla 

echo "_query dump="; 
var_dump($_query); 
//::3 ouputs: _query dump=NULL 

echo "_fooparam="; 
var_dump($_fooparam); 
//::4 ouputs: fooparam=NULL 

echo "globalfoo="; 
var_dump($fooglobal); 
//::5 ouputs: fooglobal=fooglobal 

echo "foolocal="; 
var_dump($foolocal); 
//::6 ouputs: foolocal=NULL 

echo "foonewmember="; 
var_dump($this->foonewmember); 
//::7 ouputs: foonewmember=string(12) "foonewmember" 

echo "foooldmember="; 
var_dump($this->foooldmember); 
//::8 ouputs: foooldmember=string(9) "foooldmember" 

echo "result1="; 
var_dump($this->result1); 
//::9 ouputs: result1=bool(false) 

echo "result2="; 
var_dump($this->result2); 
//::10 ouputs: result2=NULL 

} 

// more class methods ... 

} // end of class 




__________________
Thanks,

Andr? Gon?alves


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-18 23:52 UTC] sniper@php.net
Your script has serious issues...it sets some cookies?
It also has some errors, apparently caused by the missing
cookie value? This really doesn't seem like any 
problem in PHP..

 [2003-02-19 04:40 UTC] andre dot goncalves at martelozero dot com
What do you mean by serious issues? Maybe you don't understand the questions I made, or the absurd behaviour that I describe - or in the other hand, maybe I don't understand that some stupid error I made somewhere (with cookies you say) might cause this strange behaviour of PHP (you sound very natural about it).

Well I have some serious questions:

1. What's the relation between cookies and the Empty + Unavailable + Unassignable local variables and function parameters in the method's implementation?

2. What causes the script to go crazy in terms of variable value assignment?

3. Why do local vars fail to accept values from a certain point on?

4. Hhy it only happens the first time the script runs, and why only in the second time the method is called? After a code-induced & cookie-related error, you say?
 
5. How does a variable echo a value that it was not assigned? Again, how does $this->tmp2 = "whatever" makes $_query = "whatever"? And why var_dump'ing ($_query) returns NULL?

6. Why $localvar = "foo", does not make $localvar = "foo", i.e., why local vars and parameters are unavailable and unassignable?

Thanks
 [2003-02-22 18:02 UTC] andre dot goncalves at martelozero dot com
Ok, I'm sorry I didn't get any answer from you guys.

The problem is solved. I don't know how, but it suddenly stoped, after I made some random and desperate changes in the code somewhere.

What I will never understand is what kind of error in my code, that is not detected by PHP causes such abnormal behaviour.

PHP did not return any Notice, Warning, or Error message, it simply went beserk with variables. I don't really understand much about this issues, but someone told me that the stack was getting corrupted, and to look for recursive function calls. (there were none)

Anyway I think that this issue should be investigated. Not just simply say that there were "serious issues" with my code. Off course there were, but certainly not with cookies.

The thing is, if there is a reason for PHP to go nuts, it should issue some kind of warning (like it normally does).

Thanks anyway

Keep up developing this amazing thing.
 [2003-02-23 03:43 UTC] sniper@php.net
It's impossible to investigate this without any example code
that can be proven to cause such 'beserk' behaviour.

Unless you can provide such code, lets make this bogus for
now.

(parts of such code are useless, we need full script)

 [2003-04-23 20:28 UTC] elviscious at rmci dot net
This is definitely a valid bug, as I am seeing almost exactly what Andre is describing.

The current problem I am seeing is with this function below:

*************

function meta($page, $time=2){

   print "$page $time ";
   printf('<META http-equiv="refresh" content="%d; URL=%s">', $page, $time);
   printf('http-equiv="refresh" content="%d; URL=%s">\n', $page, $time); # Just to have the meta tag print to the screen

}

meta('/example/page.html');

****************

# Note: I have plugged this into a page by itself and it works as expected.  I will try to post a page that does display this problem, but currently, there is a lot of stuff to strip out before I can post it.

This would print a simple meta refresh for a page, when it works.  When it doesn't work, what I'm seeing:
'1 1 http-equiv="refresh" content="0; URL=">'

and the refresh shows up as

<META http-equiv="refresh" content="0; URL=">

Which makes no sense at all. The time right after the 'content' section shows up as a '0', which I guess means the  variable is really null.

If I change the printf statements to print strings for both, then the variable after the content print nothing, as in 'content="; URL=">'

As described before, by Andre, refreshing the page in the browser fixes the problem, unless you close the browser, or delete the session file in /tmp worked for me also.

As I said, I will try to provide some useable code to backup these wild accusations : ) but currently there are so many requires, and openldap queries that it might be awhile.

thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 04:01:30 2024 UTC