# [PATCH] destructors called after module shutdown

- Thread: https://externals.io/message/10879
- Original archive: https://news-web.php.net/php.internals/10879
- Started by Florian Schaper on 2004-07-02T21:51:44+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10879 — Florian Schaper — 2004-07-02T21:51:44+00:00

URL: https://externals.io/message/10879#10879

Currently object's destructors are called in the zend_deactivate function in
main.c after the modules
request_shutdown_func has been called (main.c -
php_call_shutdown_functions(void); ) .

Since no code should be executed after module request shutdown unexpected
behaviour might
occur like the one descibed in bug#27555 affecting the session extension.

Maybe somebody can take a look.

./regards

Florian

<?php
// Short test which saves a session in the destructor
class TestSession {
 public static $oSessionMap;

 public function __construct() {
  `session_start()`;
  if( empty($_SESSION['sessionObject']) ) {
   TestSession::$oSessionMap = array();
  } else if ( ! is_array(TestSession::$oSessionMap) ) {
   TestSession::$oSessionMap = unserialize( $_SESSION['sessionObject'] );
  } // if / else
 } // public function __construct

 public function add( $sKey, $sValue ) {
  TestSession::$oSessionMap[ $sKey ]  = $sValue;
 } // public function add

 public function get( $sKey ) {
  return TestSession::$oSessionMap[ $sKey ];
 } // public function get

 public function __destruct() {
  $_SESSION['sessionObject'] = serialize(TestSession::$oSessionMap);
 } // public function __destruct
} // class Session

$oSes = new TestSession();
echo $oSes->get("test1","testval");
$oSes->add("test1","testval");

?

---

## #10884 — Marcus Boerger — 2004-07-03T08:27:57+00:00

URL: https://externals.io/message/10879#10884 · In reply to: #10879

Hello Florian, hello Andi

  to me this is the way to go. At least the order of shutdown pieces
is correct with this patch but maybe Andi has a better idea?

regards
marcus

Friday, July 2, 2004, 11:51:44 PM, you wrote:

> Currently object's destructors are called in the zend_deactivate function in
> main.c after the modules
> request_shutdown_func has been called (main.c -
> php_call_shutdown_functions(void); ) .

> Since no code should be executed after module request shutdown unexpected
> behaviour might
> occur like the one descibed in bug#27555 affecting the session extension.
