php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58813 Late static binding and visibility issue
Submitted: 2009-08-16 08:16 UTC Modified: 2009-08-25 18:12 UTC
From: simast at gmail dot com Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5_3 CVS-2009-08-16 (dev) OS: Linux (Ubuntu)
Private report: No CVE-ID: None
 [2009-08-16 08:16 UTC] simast at gmail dot com
Description:
------------
There is something wrong with late static binding and class static variable visibility. Changing One::$var visibility to "public" fixes the issue.

Reproduce code:
---------------
class One {
	protected static $var;

	public static function getVar() {
		return static::$var;
	}
}

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

var_dump(Two::getVar());

Expected result:
----------------
string(3) "two"

Actual result:
--------------
When hits = 0 (empty cache): string(3) "two"
When hits > 0 (loading from cache): Fatal error: Access to undeclared static property: Two::$var

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-17 14:35 UTC] gopalv82 at yahoo dot com
These new fangled static scopes ... 

Thanks for the bug report, I'm looking into it.
 [2009-08-25 17:52 UTC] gopalv82 at yahoo dot com
Yup, new member to the zend_class_entry struct

zce->static_members
 [2009-08-25 18:12 UTC] gopalv82 at yahoo dot com
There's some offensively "clever" code in apc_compile.c which needs to go away.

http://news.php.net/php.pecl.cvs/12844

Out it goes. Because here we have a scenario where the 
child can actually initialize the static variable 
independently over the overriden parent. And a NULL insert
is not good enough.

Thanks for the bug report!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC