|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-08 12:14 UTC] johannes@php.net
[2007-08-08 13:25 UTC] peter dot evertz at snafu dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 16:00:02 2025 UTC |
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