From:             bugs dot php dot net at b-a-l-u dot de
Operating system: Linux (Debian Woody)
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  session_encode() encodes old data?

Description:
------------
In PHP 4.1.2 (Debian Woody) seems to be a problem with session_encode();
This problem was probably fixed already in later versions, as I receive
correct results in PHP 5.0.1 (local wampp installation of the
apachefriends package).

However - a small note in the PHP documentation regarding this problem
would have saved me a lot of debugging time. Especially if I was told at
which version this was fixed, so I might raise the minimum PHP version
requirements of my scripts or find a workaround somehow... Because of this
I am filing it as a documentation problem.

The problem is that session_encode() seems to encode old session
information or perhaps does not use $_SESSION as a source for the data to
be encoded. See the examples below for the effect.

On both PHP versions register_globals is enabled.

I am not sure if this is related to "If you enable register_globals,
session_unregister() should be used since session variables are registered
as global variables when session data is deserialized."
(http://php.net/manual/en/ref.session.php)



Reproduce code:
---------------
<?php
session_start();
print('<a href="A.php">load again</a><br />');
print(session_id().'<br />');

$_SESSION['count']++;

var_dump($_SESSION); echo '<br />';
print(session_encode().'<br />');

/* delete this line to enable "resetting" of the array
print('Resetting session array<br />');
$_SESSION = array();
var_dump($_SESSION); echo '<br />';
print(session_encode().'<br />');
/* */
?>

Expected result:
----------------
In PHP Version 5.0.1 the following happens (which looks ok) (added some
notes starting with "//"):

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> int(1) }
count|i:1; // session_encode() correctly starts with session data

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> &int(2) }
count|i:2; 

Now I enable the "reset" of the session array: 

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> &int(3) }
count|i:3;
Resetting session array
array(0) { } 
// the session_encode call correctly returns ""

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> int(1) }
count|i:1;
Resetting session array
array(0) { } 

Actual result:
--------------
In PHP 4.1.2 I get the following output: (added some notes starting with
"//")

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> int(1) } 
// no session_encode data?

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(2) }
count|i:2;

Now I enable the "reset" of the session array: 


97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(3) }
count|i:3;
Resetting session array
array(0) { } // the $_SESSION array is empty, but 
count|i:3;   // session_encode still maintains the old content?

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(4) }
count|i:4;
Resetting session array
array(0) { } 
count|i:4;   

-- 
Edit bug report at http://bugs.php.net/?id=30151&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30151&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30151&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30151&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30151&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30151&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30151&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30151&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30151&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30151&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30151&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30151&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30151&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30151&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30151&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30151&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30151&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30151&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30151&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30151&r=mysqlcfg

Reply via email to