php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36239 $_SESSION Array Assignment Fails
Submitted: 2006-02-01 05:37 UTC Modified: 2006-02-01 09:18 UTC
From: martin at itmission dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.1.2 OS: Windows
Private report: No CVE-ID: None
 [2006-02-01 05:37 UTC] martin at itmission dot com
Description:
------------
$_SESSION does not keep results when assigned an array variable.

Reproduce code:
---------------
test1.php

<?php

session_start();

echo("<a href=\"{$_SERVER['PHP_SELF']}\">click</a>");
print_r($_SESSION);
$_SESSION = array('id' => 1, 'user' => 'test');

session_write_close();

?>

test2.php

<?php

session_start();

echo("<a href=\"{$_SERVER['PHP_SELF']}\">click</a>");
print_r($_SESSION);
$row = array('id' => 1, 'user' => 'test');
$_SESSION = $row;

session_write_close();

?>

test3.php

<?php

session_start();

echo("<a href=\"{$_SERVER['PHP_SELF']}\">click</a>");
print_r($_SESSION);
$row = array('id' => 1, 'user' => 'test');
$_SESSION = $row + array();

session_write_close();

?>


Expected result:
----------------
Test1.php: Works
Test2.php: Fails
Test3.php: Works

Actual result:
--------------
Test1: clickArray ( [id] => 1 [user] => test )
Test2: clickArray ( )
Test3: clickArray ( [id] => 1 [user] => test )


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-01 09:18 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is actually correct behavior. The $_SESSION array is special, and now you\'re overwriting it removing its special capabilities.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 10:01:31 2024 UTC