|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-13 03:24 UTC] dtajchreber@php.net
-Status: Open
+Status: Bogus
[2010-12-13 03:24 UTC] dtajchreber@php.net
[2010-12-13 04:00 UTC] jstuckle at attglobal dot net
[2010-12-13 04:38 UTC] jstuckle at attglobal dot net
-Operating System: Windows 7
+Operating System: Irrelevant
-PHP Version: 5.3.4
+PHP Version: Irrelevant
[2010-12-13 04:38 UTC] jstuckle at attglobal dot net
[2010-12-13 05:17 UTC] dtajchreber@php.net
[2010-12-13 05:45 UTC] jstuckle at attglobal dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 19:00:01 2025 UTC |
Description: ------------ When an object is stored in the $_SESSION variable, the destructor is still called at the end of the script. When the object is retrieved from the $_SESSION on the next invocation, the constructor is not called, but the destructor is again called. To duplicate, place the attached code on a web server and load it. Then press the reload button multiple times to see the results. Test script: --------------- <?php class test { private $construct_count = 0; private $destruct_count = 0; public function __construct() { $this->construct_count++; echo "Constructor called.<br>\n"; } public function __destruct() { $this->destruct_count++; echo "Destructor called.<br>\n"; } } session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Test Script</title> </head> <body> <?php if (!isset($_SESSION['test'])){ echo "Session not found<br>\n"; $_SESSION['test'] = new Test(); } else echo "Session found<br>\n"; echo "<pre>\n"; print_r($_SESSION); echo "</pre>\n"; ?> </body> </html> Expected result: ---------------- Session not found Constructor called. Array ( [test] => test Object ( [construct_count:test:private] => 1 [destruct_count:test:private] => 0 ) ) After second and subsequent invocations: Session found Array ( [test] => test Object ( [construct_count:test:private] => 1 [destruct_count:test:private] => 0 ) ) Actual result: -------------- After first invocation: Session not found Constructor called. Array ( [test] => test Object ( [construct_count:test:private] => 1 [destruct_count:test:private] => 0 ) ) Destructor called. After second and subsequent invocations: Session found Array ( [test] => test Object ( [construct_count:test:private] => 1 [destruct_count:test:private] => 1 ) ) Destructor called. Note: destruct_called increments on each invocation. construct_count does not.