ID: 42239 User updated by: peter dot evertz at snafu dot de Reported By: peter dot evertz at snafu dot de Status: Bogus Bug Type: Session related Operating System: Linux 2.6.18 PHP Version: 5.2.4RC1 New Comment:
Sorry for writing a Bug-report. And thank you for your hint for a work-around. Are there plans to remove this limitation ? Previous Comments: ------------------------------------------------------------------------ [2007-08-08 12:14:42] [EMAIL PROTECTED] Objects of internal classes can't be serialized and therefore can't be stored in a session. You might use __sleep/__wakeup magic methods to store the timestamp in the session and then restore it. ------------------------------------------------------------------------ [2007-08-08 00:02:23] peter dot evertz at snafu dot de Description: ------------ I found this while using propel. It uses DateTime class for storing. After retrieving the class from a Session the member is broken. The code creates a session variabel "v" with the given class if not found.On the second call to the script the class is retrievies from session. The member x is broken. Reproduce code: --------------- <?php class c { protected $v; function print_type() { if ( $this->v instanceof DateTime ) { print "x is DateTime\n"; } } function get_v() { return $this->v; } function set_v($i) { $this->v=$i; } } session_start(); if ( !isset($_SESSION["x"] )) { $x = new c(); $x->set_v( new DateTime()); $_SESSION["x"]=$x; print "New object created\n"; } $_SESSION["x"]->print_type(); print $_SESSION["x"]->get_v()->format("d.m.Y"); ?> Expected result: ---------------- First call: New object created x is DateTime 08.08.2007 Second call: x is DateTime 08.08.2007 Actual result: -------------- First call: New object created x is DateTime 08.08.2007 Second call: x is DateTime Warning: DateTime::format(): The DateTime object has not been correctly initialized by its constructor in /home/peter/workspace/Kurse/html/t1.php on line 28 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42239&edit=1