php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #22068 Access $_SESSION
Submitted: 2003-02-05 05:23 UTC Modified: 2003-02-05 20:52 UTC
From: AchimWinkelmann at web dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.0 OS: Windows XP
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: AchimWinkelmann at web dot de
New email:
PHP Version: OS:

 

 [2003-02-05 05:23 UTC] AchimWinkelmann at web dot de
The manual says at topic XCIII. SESSION HANDLING FUNCTIONS under headline EXAMPLES within the NOTE, 'you do not need to use the global keyword for $_SESSION'. 

In fact you 'may not use the global keyword' when accessing $_SESSION from within a function, otherwise a different global variable seems to be created/accessed (PHP 4.3.0, WinXP)!

Maybe it is no bug, but I miss any sematically sense.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-05 05:24 UTC] derick@php.net
Documentation problem
 [2003-02-05 14:31 UTC] nicos@php.net
The documentation is clear enough to me (us).

Using the global keyword on any $_* shouldn't create a new variable. If it does, this is not a documentation bug. I verified with PHP4.3 and 5.0 (ZE2), it doesn't. 

Not a bug -> Bogus.

Feel free to post a new bug if you feel we are wrong.
 [2003-02-05 20:52 UTC] AchimWinkelmann at web dot de
Bogus? 

PAGE 1  (test_index.php):
===========================================================
<?  include ('test_session.inc');
    session_start ();
?>
<HTML><HEAD><TITLE>Test session</TITLE></HEAD>
<BODY TEXT="#000000" LINK="#FFCC00" ALINK="#33FF00" VLINK="#FFCC00" bgcolor="#FFFFFF">
<br>
<u><i>test_index.php</i></u><br>
<br>
<?  sessRESTORE();
 
    $_SESSION['direkt'] = 'Wert';
    sessVAR( 'test', '1234' ); 
    
    print( "<i>session_id() = '".session_id()."'</i><br>\r\n" );

    print( "<i>\$_SESSION['test'] = '".((isset($_SESSION['test']))?$_SESSION['test']:'not set')."'</i><br>\r\n" );
    print( "<i>\$test = '".((isset($test))?$test:'not set')."'</i><br>\r\n" );
    print( "<i>\$_SESSION['direkt'] = '".((isset($_SESSION['direkt']))?$_SESSION['direkt']:'not set')."'</i><br>\r\n" );
    print( "<i>\$direkt = '".((isset($direkt))?$direkt:'not set')."'</i><br>\r\n" );
?>
<br>
<a href="test_start.php?<?=SID?>"><b>next</b></a><br>
</BODY></HTML>
-----------------------------------------------------------

PAGE 2  (test_start.php):
===========================================================
<?  include ('test_session.inc');
    session_start ();
?>
<html><head><title>Test session</title></HEAD>
<BODY TEXT="#000000" LINK="#FFCC00" ALINK="#33FF00" VLINK="#FFCC00" bgcolor="#FFFFFF">
<br>
<i><u>test_start.php</u></i><br>
<br>
<?  sessRESTORE();

    print( "<i>session_id() = '".session_id()."'</i><br>\r\n" );
    
    print( "<i>\$_SESSION['test'] = '".((isset($_SESSION['test']))?$_SESSION['test']:'not set')."'</i><br>\r\n" );
    print( "<i>\$test = '".((isset($test))?$test:'not set')."'</i><br>\r\n" );
    print( "<i>\$_SESSION['direkt'] = '".((isset($_SESSION['direkt']))?$_SESSION['direkt']:'not set')."'</i><br>\r\n" );
    print( "<i>\$direkt = '".((isset($direkt))?$direkt:'not set')."'</i><br>\r\n" );
?>
<br>
<a href="test_index.php?<?=SID?>"><b>back</b></a>&nbsp;
</body></html>
-----------------------------------------------------------

FUNCTIONS (test_session.inc):
===========================================================
<?
  function sessVAR ($name, $wert) {
    global $_SESSION;
    $_SESSION[$name] = $wert;
    eval('global $'.$name.'; $'.$name.'=$_SESSION[\''.$name.'\'];');
  }
	
  function sessRESTORE () {
    global $_SESSION;
    while ( list ($key, $value) = each ($_SESSION) ) {
      eval( 'global $'.$key.'; $'.$key.'=$_SESSION[\''.$key.'\'];' );
      print( 'sessRESTORE $'.$key."<br>\r\n" );
    }
  }
?>
-----------------------------------------------------------


First Test - PAGE 1 displays:
=============================
test_index.php

session_id() = 'a8422f455c75aec5a3654c2894f7b4f2'
$_SESSION['test'] = '1234'
$test = '1234'
$_SESSION['direkt'] = 'Wert'
$direkt = 'not set'

next

First Test - PAGE 2 displays:
=============================
test_start.php

session_id() = 'a8422f455c75aec5a3654c2894f7b4f2'
$_SESSION['test'] = 'not set'
$test = 'not set'
$_SESSION['direkt'] = 'not set'
$direkt = 'not set'

back  

First Test - continued:
=======================
If I goon switching between these two pages, I get the same results for each page as shown above.


For the following second test the statements 'global $_SESSION;' within the functions of 'test_session.inc' are deactivated!

Second Test - PAGE 1 displays:
==============================
test_index.php

session_id() = '91f0a63c90e8a567610a3a9ec5195202'
$_SESSION['test'] = '1234'
$test = '1234'
$_SESSION['direkt'] = 'Wert'
$direkt = 'not set'

next

Second Test - PAGE 2 displays:
==============================
test_start.php

sessRESTORE $direkt
sessRESTORE $test
session_id() = '91f0a63c90e8a567610a3a9ec5195202'
$_SESSION['test'] = '1234'
$test = '1234'
$_SESSION['direkt'] = 'Wert'
$direkt = 'Wert'

back

Second Test - continued:
========================
If I goon switching between these two pages, I get the  correct results as shown in Page 2 Display!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jun 14 13:01:23 2021 UTC