#49432 [NEW]: $_SESSION cannot store objects and resources
From: jost dot boekemeier at googlemail dot com
Operating system: Any
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: $_SESSION cannot store objects and resources
Description:
------------
The session documentation does not make it clear that PHP cannot
(logically and in its current implementation) store objects or resources.
This lack of specification makes it hard for external libraries to respond
to bug reports like this one: http://bugs.php.net/bug.php?id=13840&edit=1.
(BTW: In bug#13840 Mr. Holzgreve states that "php sessions can store every
PHP data type including objects". This is clearly WRONG and shows that even
PHP devs don't understand the PHP scripting language.)
We've had a similar bug report for the PHP/Java Bridge. This person wanted
to store a Java object into the session.
Please add the following to the _SESSION documentation:
"PHP sessions can only store PHP /values/, for example exact or inexact
numbers. They *cannot* store any other PHP data types, including resources
and objects. If you want to store complex data in the session, serialize
the data into a string value first."
Please note that I have filed this as a documentation bug, not a bug in
the PHP implementation.
Reproduce code:
---------------
<?php
class X {
var $destroyed;
function __sleep() { echo "s"; if ($this->destroyed) { echo("\nerror:
destroyed"); sleep (10); exit(1);} /*not reached*/ }
function __destruct() { echo "d"; $this->destroyed = true; }
function __construct() { echo "c"; $this->destroyed = false; }
}
session_start();
$x= new X();
$_SESSION["X"]=$x;
?>
Expected result:
----------------
The above script should not call __destruct() before __sleep();
Actual result:
--------------
__destruct() is called before __sleep()
--
Edit bug report at http://bugs.php.net/?id=49432&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49432&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49432&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49432&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49432&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49432&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49432&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49432&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49432&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49432&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49432&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49432&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49432&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49432&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49432&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49432&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49432&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49432&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49432&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49432&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49432&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49432&r=mysqlcfg
Thread (9 messages)
- jost dot boekemeier at googlemail dot com