|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-04 00:54 UTC] tstarling at wikimedia dot org
Description: ------------ The request function of the session module calls custom session save handlers. Because modules are shut down after zend_call_destructors() is called, this exposes the weird and apparently broken behaviour of zend_call_destructors() to the user space. Its effect is to delete all global variables with a reference count of 1, but only if they hold an object. Global variables which are referenced from anywhere, including other global variables, are not deleted. Ideally, I would like session save handlers to have reliable access to global variables. That probably means calling them before the user-defined __destruct() functions, say with an extra hook into php_request_shutdown(). Failing that, I would like the behaviour to be consistent and predictable, so that we don't end up with strange regressions like the one observed here: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83140#c14601 Test script: --------------- <?php function noop() {} function save() { debug_zval_dump( $GLOBALS['a'] ); debug_zval_dump( $GLOBALS['b'] ); debug_zval_dump( $GLOBALS['c'] ); } class Foo {} $a = new Foo; $b = new Foo; $c =& $b; session_set_save_handler( 'noop', 'noop', 'noop', 'save', 'noop', 'noop' ); session_start(); Expected result: ---------------- object(Foo)#1 (0) refcount(2){ } object(Foo)#2 (0) refcount(1){ } object(Foo)#2 (0) refcount(1){ } Actual result: -------------- Notice: Undefined index: a in /home/tstarling/src/php/stuff/weird-shutdown_destructors.php on line 5 NULL refcount(1) object(Foo)#2 (0) refcount(1){ } object(Foo)#2 (0) refcount(1){ } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 04:00:01 2025 UTC |
If you add this to your code, it works around the problem, while still closing the session as late as possible I think : <?php register_shutdown_function('shutdown_session'); function shutdown_session() {register_shutdown_function('session_write_close');} ?>