php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59112 Late static binding and serializing with sessions causes errors
Submitted: 2010-03-13 03:23 UTC Modified: 2010-03-19 17:23 UTC
From: josh dot varner at gmail dot com Assigned:
Status: Duplicate Package: APC (PECL)
PHP Version: 5.3.1 OS: Mac OS X 10.6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 - 28 = ?
Subscribe to this entry?

 
 [2010-03-13 03:23 UTC] josh dot varner at gmail dot com
Description:
------------
Using: APC from Subversion (checked out on 2010-03-13, 
revision #296139) with PHP 5.3.1

I'm getting a fatal error when using late static binding 
features within a serialize() function for storing an object 
in a session.  I'm not familiar with the internals of this, 
so the fact that it's happening within the serialize() call 
may be irrelevant.

If I remove the APC extension from php.ini, I do not receive 
any errors-- the code behaves as expected.

I based this sample code on the following but, which I found 
while trying to troubleshoot this.

http://pecl.php.net/bugs/bug.php?id=16795

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

class One implements Serializable {
	protected static $var;

	public static function getVar() {
		return static::$var;
	}
	
	public function serialize() {
	    return serialize(array('var' => static::getVar()));
	}
	
	public function unserialize($str) {
	    $data = unserialize($str);
	}
}

class Two extends One {
	public static $var = 'two';
}

session_start();

var_dump($_SESSION);

$_SESSION['blah'] = new Two();


Expected result:
----------------
View #1: var_dump output empty, nothing else
View #2 and on: var_dump output should show simple dump of the 
Two object.

Actual result:
--------------
View #1: fine
View #2: fine
View #3: The following:

array(1) { ["blah"]=> object(Two)#1 (0) { } } 
Fatal error: Access to undeclared static property: Two::$var 
in /webroot/apc_test.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-19 17:23 UTC] josh dot varner at gmail dot com
Apologies-- I finally tracked down the cause of this bug, 
which is related to the shutdown sequence and such.  Calling 
session_write_close() explicitly seems to fix this, though I 
really hope that this is addressed in the future.

See:
http://pecl.php.net/bugs/bug.php?id=16745
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC