ID:               29032
 Comment by:       anthony at ectrolinux dot com
 Reported By:      antonr at game dot permonline dot ru
 Status:           Open
 Bug Type:         Session related
 Operating System: Irrelevant
 PHP Version:      5CVS-2004-07-06 (dev)
 New Comment:

For reference, this bug appears to be synonymous to bug #30578, with
the same cause but a different effect.


Previous Comments:
------------------------------------------------------------------------

[2004-10-26 02:40:15] auroraeosrose at hotmail dot com

Modifying $_SESSION in the destructor ONLY works if you call
unset($object) before the end of your script, however this is a pain in
the rear - and if you have references to that object elsewhere it
doesn't work properly.

There is a workaround... You CAN use register_shutdown_function in the
constructor of your class

      public function __construct()
        { 
register_shutdown_function(array($this, '__destruct');
        } 

and then the destruct is called early enough that you can modify
$_SESSION. But this defeats the whole purpose of a destructor - I could
do that in every class if php5 didn't support destructors (in fact I did
in php4) but I thought the point was to eliminate messy workarounds. 
Now why in the world the sessions are closed in between when shutdown
functions and destructors are called is beyond me.

------------------------------------------------------------------------

[2004-07-06 16:58:15] antonr at game dot permonline dot ru

Description:
------------
Session are closed before all object destructors executed. It seems to
be wrong, cause objects desctructors may save information in opened
session.


Reproduce code:
---------------
<?php

  class MySession
    { public $number; 
      public function __construct()
        { session_start();
          $this->number = @$_SESSION["number"];
        }
      public function Process()
        { $this->number++;
        }
      public function __destruct()
        { $_SESSION["number"] = $this->number;
          session_write_close();
        }
    }

  $ss = new MySession();
  $ss->Process();
  echo $ss->number;

?>


Expected result:
----------------
With every page reloading number in the page must increase by 1.

Actual result:
--------------
Everytime number is equal 1.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=29032&edit=1

Reply via email to