php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53141 autoload misbehaves if called from closing session
Submitted: 2010-10-23 10:36 UTC Modified: 2010-11-02 19:37 UTC
From: ladislav at marek dot su Assigned: felipe (profile)
Status: Closed Package: SPL related
PHP Version: 5.3SVN-2010-10-23 (SVN) OS: GNU Linux
Private report: No CVE-ID: None
 [2010-10-23 10:36 UTC] ladislav at marek dot su
Description:
------------
SPL autoload triggers fatal error if is called from currently closing session. 
With __autoload function scripts works fine.

Test script:
---------------
spl_autoload_register(function ($class) {
    var_dump("Loading $class");
    eval('class Bar {}');
});

class Foo
{
    function __sleep()
    {
        new Bar;
        return array();
    }
}

session_start();
$_SESSION['foo'] = new Foo;

Expected result:
----------------
string(11) "Loading Bar"

Actual result:
--------------
Fatal error: spl_autoload(): Class Bar could not be loaded in 
/var/www/hosts/tests.l/index.php on line 14

Patches

add-session-dependency-to-spl (last revision 2010-11-01 18:17 UTC by ladislav at marek dot su)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-23 16:55 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2010-10-23 16:55 UTC] felipe@php.net
I got the expected result when testing on the 5.3 SVN version. Are you actually using the lastest SVN version?
 [2010-10-23 17:38 UTC] ladislav at marek dot su
-Status: Feedback +Status: Open
 [2010-10-23 17:38 UTC] ladislav at marek dot su
I updated PHP from the SVN (rev 304664). With PHP compiled only with "--with-config-file-path=/etc/php" script runs as 
expected, but fails with configure options:

--with-config-file-path=/etc/php --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --with-curl --with-
curlwrappers --enable-dba --enable-ftp --with-gd --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-zlib-
dir=/usr/include --with-xpm-dir=/usr/include --with-freetype-dir=/usr/lib --enable-gd-native-ttf --with-gettext --with-mhash 
--with-imap --with-imap-ssl --with-ldap --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-
pdo-mysql=mysqlnd --with-pdo-pgsql --with-pgsql --enable-shmop --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-
sysvmsg --with-tidy --with-xmlrpc --with-xsl --enable-zip --enable-intl --enable-fpm
 [2010-10-24 13:51 UTC] ladislav at marek dot su
I can reproduce it with '--with-mysql=mysqlnd' configuration.
 [2010-11-01 19:17 UTC] ladislav at marek dot su
It looks like that --with-mysql=mysqlnd configuration causes different order of 
extensions, so SPL extension is destroyed before the session is.

Adding session dependency to SPL fixes this bug (I'm not sure if is it correct 
way).
 [2010-11-02 19:34 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=305034
Log: - Fixed bug #53141 (autoload misbehaves if called from closing session)
  patch by: ladislav at marek dot su
 [2010-11-02 19:37 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-11-02 19:37 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the patch, I committed a slighty modified version, I changed OPTIONAL to REQUIRED as SPL is not disableable.
 [2010-11-02 21:51 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=305038
Log: - Fixed config.m4 to complete the fix for bug #53141 (thanks Johannes)
 [2011-05-20 03:54 UTC] bugs dot php dot net at elyobo dot net
I have the same problem in PHP 5.2.10 (Ubuntu version: 5.2.10.dfsg.1-2ubuntu6.5), 
which doesn't have mysqlnd.  I can work around it by doing my thing in 
__destruct() instead, which works, but I'm not sure that this bug is only related 
to mysqlnd.
 [2011-05-20 03:56 UTC] bugs dot php dot net at elyobo dot net
Also possibly relevant, calling spl_autoload_functions() in __sleep() causes PHP 
to segfault in 5.3.3 (Debian version: 5.3.3-7+squeeze1) and the 5.2.10 version 
mentioned above.
 [2011-05-20 10:28 UTC] ladislav at marek dot su
This bug was fixed in PHP 5.3.4, so yours 5.3.3 and 5.2.10 is still affected.

Its not caused by mysqlnd itself, it can be any other extension, which affects 
order of how extensions are destroyed. You should update.
 [2011-05-20 10:32 UTC] bugs dot php dot net at elyobo dot net
OK, thanks; I had the impression from this that it was specific to mysqlnd, so I 
assumed that it wasn't present in the 5.2.x series (as it doesn't have mysqlnd).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 16 11:01:30 2024 UTC