|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-08-14 07:48 UTC] gmtfn at yahoo dot com
[2008-08-14 17:42 UTC] jani@php.net
[2008-08-14 23:04 UTC] gmtfn at yahoo dot com
[2008-08-22 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 19:00:02 2025 UTC |
Description: ------------ Calling serialize() on an object whose name is the same as the key under which it's saved in $_SESSION makes the object unusable (its methods can't be called. If I store store a serialized version of the object under a key that's different from the name of the variable that points to the object, then everything works fine. If this is by design and must remain this way, I want to tell you that this is VERY counterintuitive and must be prominently documented. I can reproduce this on a Linux server (with PHP 5.2.5 and 5.2.6) but not on Windows Vista. Reproduce code: --------------- <?php session_start(); ob_start(); class GoodObject { private $count = 0; public function doSmth() { echo "$this->count <br>"; $this->count++; } } if(!isset($_SESSION['myObj'])) { $myObj = new GoodObject(); } else { $s = $_SESSION['myObj']; $myObj = unserialize($s); } $myObj->doSmth(); $s = serialize($myObj); $_SESSION['myObj'] = $s; $myObj->doSmth(); // this fails on the second page load ?> Expected result: ---------------- Converting an object to a string should not change the object, and the last statement in this script should output the value of $count. Actual result: -------------- On the second load of the page, I get this: Fatal error: Call to a member function doSmth() on a non-object in [path to the file] on line 26