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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: josh dot varner at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 12:01:29 2025 UTC