php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3261 sess_register doesn't register global variables correctly
Submitted: 2000-01-20 12:40 UTC Modified: 2000-11-19 08:14 UTC
From: stas at zend dot com Assigned: stas (profile)
Status: Closed Package: *General Issues
PHP Version: 4.0 Latest CVS (20/01/2000) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stas at zend dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-13 11:33 UTC] sterling at cvs dot php dot net
Session variables are not in the global namespace unless specified.  This is the correct behavior.
 [2000-05-14 04:33 UTC] stas at zend dot com
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?

                            }

 [2000-05-14 04:34 UTC] stas at zend dot com
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?

                            }

 [2000-07-30 09:46 UTC] zak@php.net
Has there been any progress on this bug?
 [2000-08-15 09:38 UTC] waldschrott@php.net
This is a dup.
 [2000-08-15 10:28 UTC] waldschrott@php.net
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;
}


 [2000-08-15 10:29 UTC] waldschrott@php.net
Note, the manual says:
"If both track_vars and register_globals are enabled, then
the globals variables and the $HTTP_SESSION_VARS entries
will reference the same value."
Thus a variable made global a before session_start()?s
should be updated accordingly
 [2000-11-19 08:14 UTC] stas@php.net
Fixed in CVS.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 08:01:30 2024 UTC