|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-01-20 12:40 UTC] stas at zend dot com
The script:
<?php
session_name("XSession");
function start() {
global $count;
session_start();
session_register("count");
var_dump($count);
}
function see() {
global $count;
print "Here: $count<br>";
}
$count=0;
start();
see();
$count++;
?>
shows:
int(0) Here: N
where N is the correct current value of $count. Note that if I put global after session_register, it works OK.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 01:00:01 2025 UTC |
What do you mean "unless specified"? Did you look at the code: function start() { global $count; // If *this* is not specification of global, what is? session_start(); session_register("count"); var_dump($count); // Which "count" is 0 here? If global, why it isn't 0 below? // If local, what happened to "global" $count I just defined and // how do I specify that I want *that* *global* count, and not // want to create new local one to override old one? } function see() { global $count; print "Here: $count<br>"; // And *how exactly* I got the right value here if session variable wasn't global? }What do you mean "unless specified"? Did you look at the code: function start() { global $count; // If *this* is not specification of global, what is? session_start(); session_register("count"); var_dump($count); // Which "count" is 0 here? If global, why it isn't 0 below? // If local, what happened to "global" $count I just defined and // how do I specify that I want *that* *global* count, and not // want to create new local one to override old one? } function see() { global $count; print "Here: $count<br>"; // And *how exactly* I got the right value here if session variable wasn't global? }duped out 6161, following code doesn?t behave equally (register_globals=on) function increment_0() { global $a; session_start(); $a += 1; } function increment_1() { session_start(); global $a; $a += 1; }