[PHP] Global Var Disappearing After Function
Hey list, I have a very odd problem which has been driving me crazy for two days. I've been trying to debug my code and gave up. I finally coded a very simple representation of what the code does, and I get the same problem. However, I still don't understand what's causing it. The representational code: http://pastie.org/private/fz3lgvsjopz3dhid8cf9a As you can see, it's very simple. A variable is set, then a function is called which modifies the variable in the global scope. However, the modifications CANNOT BE SEEN after the function is called. The output from the script is here: http://pastie.org/private/29r5mrr1k7rtqmw7eyoja As you can see, the modifications in do_test() cannot be seen after the function is called. What is causing this? And how can I fix it? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Var Disappearing After Function
On Mon, Mar 22, 2010 at 4:58 PM, APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a very odd problem which has been driving me crazy for two days. I've been trying to debug my code and gave up. I finally coded a very simple representation of what the code does, and I get the same problem. However, I still don't understand what's causing it. The representational code: http://pastie.org/private/fz3lgvsjopz3dhid8cf9a As you can see, it's very simple. A variable is set, then a function is called which modifies the variable in the global scope. However, the modifications CANNOT BE SEEN after the function is called. The output from the script is here: http://pastie.org/private/29r5mrr1k7rtqmw7eyoja As you can see, the modifications in do_test() cannot be seen after the function is called. What is causing this? And how can I fix it? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I believe line 8 detaches the variable $Session that exists inside the function from the global variable that exists outside the function. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Var Disappearing After Function
On Mon, 22 Mar 2010 16:58:33 -0400 APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a very odd problem which has been driving me crazy for two days. I've been trying to debug my code and gave up. I finally coded a very simple representation of what the code does, and I get the same problem. However, I still don't understand what's causing it. The representational code: http://pastie.org/private/fz3lgvsjopz3dhid8cf9a As you can see, it's very simple. A variable is set, then a function is called which modifies the variable in the global scope. However, the modifications CANNOT BE SEEN after the function is called. The output from the script is here: http://pastie.org/private/29r5mrr1k7rtqmw7eyoja As you can see, the modifications in do_test() cannot be seen after the function is called. What is causing this? And how can I fix it? Thanks! From PHP.net: If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [1] [1] http://php.net/manual/en/function.unset.php -- Peter van der Does GPG key: E77E8E98 IRC: Ganseki on irc.freenode.net Twitter: @petervanderdoes WordPress Plugin Developer Blog: http://blog.avirtualhome.com Forums: http://forums.avirtualhome.com Twitter: @avhsoftware -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Var Disappearing After Function
On Mon, Mar 22, 2010 at 5:13 PM, Peter van der Does pvanderd...@gmail.com wrote: On Mon, 22 Mar 2010 16:58:33 -0400 APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a very odd problem which has been driving me crazy for two days. I've been trying to debug my code and gave up. I finally coded a very simple representation of what the code does, and I get the same problem. However, I still don't understand what's causing it. The representational code: http://pastie.org/private/fz3lgvsjopz3dhid8cf9a As you can see, it's very simple. A variable is set, then a function is called which modifies the variable in the global scope. However, the modifications CANNOT BE SEEN after the function is called. The output from the script is here: http://pastie.org/private/29r5mrr1k7rtqmw7eyoja As you can see, the modifications in do_test() cannot be seen after the function is called. What is causing this? And how can I fix it? Thanks! From PHP.net: If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [1] [1] http://php.net/manual/en/function.unset.php Ah ha! I was looking on the php.net/global page for hints, but didn't see any. I should've looked on the unset page. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Var Disappearing After Function
APseudoUtopia wrote: On Mon, Mar 22, 2010 at 5:13 PM, Peter van der Does pvanderd...@gmail.com wrote: On Mon, 22 Mar 2010 16:58:33 -0400 APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a very odd problem which has been driving me crazy for two days. I've been trying to debug my code and gave up. I finally coded a very simple representation of what the code does, and I get the same problem. However, I still don't understand what's causing it. The representational code: http://pastie.org/private/fz3lgvsjopz3dhid8cf9a As you can see, it's very simple. A variable is set, then a function is called which modifies the variable in the global scope. However, the modifications CANNOT BE SEEN after the function is called. The output from the script is here: http://pastie.org/private/29r5mrr1k7rtqmw7eyoja As you can see, the modifications in do_test() cannot be seen after the function is called. What is causing this? And how can I fix it? Thanks! From PHP.net: If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [1] [1] http://php.net/manual/en/function.unset.php Ah ha! I was looking on the php.net/global page for hints, but didn't see any. I should've looked on the unset page. Thanks! Really no reason to unset() it anyway since you do this: $Session = $UserInfo; -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] global var.
hello all, $variable = $id; // some other stuff @mysql_query here $id = mysql_insert_id(); to the question: How do I get $id from insert_id() to pass to $variable above? Hard to explain the situation i am in, but the query has to be below $variable, is it possible to 'globalize' $id so it passes to the top $variable? first time i ever ran into this problem. Thanks in advanced. cheers, - Sebastian
RE: [PHP] global var.
Hi Sebastian, $variable = $id; // some other stuff @mysql_query here $id = mysql_insert_id(); How do I get $id from insert_id() to pass to $variable above? Hard to explain the situation i am in, but the query has to be below $variable ::blink:: Perhaps something like: $loc = $PHP_SELF. ?variable=. $id; header(Location:. $loc); You'd have to put something in to stop an infinte loop though. Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global var.
Putting an sign in front of the $id in the first line should do the trick: $variable = $id; A short example: $bar = 0; $foo = $bar; $bar = 2; print $foo; //prints 2 __ Marcus Rasmussen [EMAIL PROTECTED] www.marcusr.dk - On 31-03-2003 at 19:56 Sebastian wrote: - hello all, $variable = $id; // some other stuff @mysql_query here $id = mysql_insert_id(); to the question: How do I get $id from insert_id() to pass to $variable above? Hard to explain the situation i am in, but the query has to be below $variable, is it possible to 'globalize' $id so it passes to the top $variable? first time i ever ran into this problem. Thanks in advanced. cheers, - Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global var.
Hmm, interesting.. i dunno why it doesn't work for me, here is a bit of the code, $var isn't getting the output of $id, any ideas? $var = $id; if( ! $forg = resizer_main(image,image_$var, blah, blah); $org = getimagesize( $root/$forg ); $result = @mysql_query(INSERT INTO images blah blah.); $id = mysql_insert_id(); cheers, Sebastian - Original Message - From: Marcus Rasmussen [EMAIL PROTECTED] Putting an sign in front of the $id in the first line should do the trick: $variable = $id; A short example: $bar = 0; $foo = $bar; $bar = 2; print $foo; //prints 2 __ Marcus Rasmussen [EMAIL PROTECTED] www.marcusr.dk - On 31-03-2003 at 19:56 Sebastian wrote: - hello all, $variable = $id; // some other stuff @mysql_query here $id = mysql_insert_id(); to the question: How do I get $id from insert_id() to pass to $variable above? Hard to explain the situation i am in, but the query has to be below $variable, is it possible to 'globalize' $id so it passes to the top $variable? first time i ever ran into this problem. Thanks in advanced. cheers, - Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global var.
On Tuesday 01 April 2003 11:59, Sebastian wrote: Hmm, interesting.. i dunno why it doesn't work for me, here is a bit of the code, $var isn't getting the output of $id, any ideas? Are you sure that $id contains what you think it contains? Also could you explain the reason why your code is laid out the way it is? Line 1 $var = $id; Line 2 if( ! $forg = resizer_main(image,image_$var, blah, blah); Line 3 $org = getimagesize( $root/$forg ); Line 4 $result = @mysql_query(INSERT INTO images blah blah.); Line 5 $id = mysql_insert_id(); In Line 2, $var will contain whatever $id contained in Line 1. IOW if the value of $id was not defined before Line 1, then $var will be similarly undefined. Is that your intention? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Logic is a systematic method of coming to the wrong conclusion with confidence. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] global var or passing a parameter in classes ?
Hello, here is my problem : I have a class A and I instanciate this class at the beginninf of my script. I have another class B and in some functions of this class B, I need to access the instance of the class A. So in the functions of the class B, to access the class A, is it better to receive a reference of the class A in the contructor of the class B and then store the reference into a variable of the class B OR is it better to declare global $foo; at the beginning of the functions of the class B where I need to access the instance of the class A ($foo is the name of the instance of my class A) ??? Thanks a lot -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php