php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63375 Pointer to the session dosnt work properly
Submitted: 2012-10-27 09:06 UTC Modified: 2012-10-27 15:51 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dino2150 at poczta dot fm Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.4Git-2012-10-27 (snap) OS: Win XP64
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dino2150 at poczta dot fm
New email:
PHP Version: OS:

 

 [2012-10-27 09:06 UTC] dino2150 at poczta dot fm
Description:
------------
What I'm actually trying to do is to create pointer to session.
Ok. Piece of cake.
STEP:1
----------------
session_start();
$a = &$_SESSION;
$a[5] = 555;

 -> RUN THE SCRIPT NOW;
back to edit:

session_start();
$a = &$_SESSION;
$a[5] = 555;
print_r($_SESSION);

this echoes correctly ;) 

STEP:2
-----------------
Let's try to zero-memory session data.

session_start();
$a = &$_SESSION;
$_SESSION=NULL; 
$a[5] = 55;
$_SESSION['abc']=555;
print_r($_SESSION);

At this point $_SESSION contains two elements.
No wonder, right?  Yea..right...

Now back to edit:

session_start();
print_r($_SESSION);

At this point session contains only ONE element?
WTF happend to the $_SESSION[5]=55; it was there before... 

My first shot was to unset session data with session_unset so i repleaced 
SESSION=NULL with session_unset(). This gives me the same effect.

I also took a chance with session_destroy ;)  but then the SESSION table was empty (and that makes perfecly sense).

However its hard to understand why $_SESSION table is saved partialy and not including values setted by $_SESSION reference, and WHY THIS ONLY HAPPEND WHEN I DO SOMETHING WITH THIS TABLE to erase it ;P

Test script:
---------------
TEST SCIRPT IS PART OF DESCRIPTION.

Expected result:
----------------
All variables setted by SESSION reference after calling session_unset() are expected to stay in SESSION.

So:
    first i make session ref: $a = &$_SESSION;
    then i zero-memory session by session_unset();
    then i set something to session by ref.  $a[5]=55;
    and i expected this to stay in session.

Actual result:
--------------
If i use session_unset() or nullarize session by $_SESSION=NULL and then set variables by session reference...The variables set by session reference are gone after script ends.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-27 09:08 UTC] dino2150 at poczta dot fm
Btw: My version is 5.4.3 if it helps!
 [2012-10-27 09:45 UTC] dino2150 at poczta dot fm
The problem was different then described.
SESSION just cant contain numerical keys...
Din't know that before.
 [2012-10-27 09:45 UTC] dino2150 at poczta dot fm
-Status: Open +Status: Closed
 [2012-10-27 15:51 UTC] rasmus@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC