php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15289 Global variables do not work with session.
Submitted: 2002-01-29 22:13 UTC Modified: 2002-01-30 04:52 UTC
From: brubla at seznam dot cz Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.1.1 OS: Linux
Private report: No CVE-ID: None
 [2002-01-29 22:13 UTC] brubla at seznam dot cz
Global variable will be registered in session only first time. When you will be refreshing page with following code, it will count only to 2.

<?php
session_start();
global $counter; //when you remove this row, all will work properly
session_register("counter");
$counter++;
echo $counter;
?>

When you remove row with "global $counter;" page will count to 3, 4, 5...

Both variants of code works properly with PHP 4.0.6 (on Windows 2000).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-30 02:53 UTC] derick@php.net
1. Using global in a non-function scope doesn't make any sense.
2. When doing 'global $counter' you're setting a reference from $counter to $GLOBALS['counter'] and thus breaking the reference to the session hashes

Not a bug (but rather a bug in older versions).
Making this bogus.
 [2002-01-30 04:52 UTC] brubla at seznam dot cz
You are right, but this construction 'global $counter' in non-function scope is using for example phpWebsite in included files to be sure to declare global variable if file is included in function scope. 

This is why phpWebsite is incompatible with 4.1.1. (is not possible to administer phpWebsite).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 10:01:31 2024 UTC