From: Operating system: Linux PHP version: 5.3SVN-2011-03-03 (SVN) Package: Scripting Engine problem Bug Type: Bug Bug description:Destruction of some global variables before session write handler callback
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){ } -- Edit bug report at http://bugs.php.net/bug.php?id=54157&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54157&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54157&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54157&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54157&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54157&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54157&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54157&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54157&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54157&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54157&r=support Expected behavior: http://bugs.php.net/fix.php?id=54157&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54157&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54157&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54157&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54157&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54157&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54157&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54157&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54157&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54157&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54157&r=mysqlcfg
