|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44457 Late static binding not available for static properties
Submitted: 2008-03-17 17:06 UTC Modified: 2008-03-17 19:24 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: ken at gizzar dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-03-17 (snap) OS: Mac OS X
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-03-17 17:06 UTC] ken at gizzar dot com
Late static binding not available for static properties. A very critical 
use case for PHP 5.3's late static binding is the ActiveRecord pattern. 
An example implementation would have the ActiveRecord abstract class to 
dynamically create objects of found records. The metadata about each 
table should be kept with each ActiveRecord class's static scope. This 
is simply not doable even with the new late static binding functionality 
of PHP 5.3.

Basically the same question as #44315, but it's really a design flaw in 
the PHP 5.3 scripting engine to not include a way for the parent class 
to dynamically create static properties. If the resolution is "no fix," 
then I'll be forced to create a metadata static variable which is 
(namespaced and) shared by all the classes extending the AR class.

Reproduce code:

class P 
	public static $v = "parent";
	public static function foo()
		static::$v = "child";
		echo static::$v . "\n";

class C extends P


echo P::$v . "\n";
echo P::$v . "\n";


Expected result:
// RESULTS: foo() creates a static property for the child class and sets 
it according to the static:: scope

Actual result:
// RESULTS: static:: only respects the static property in the parent P 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-17 19:24 UTC]
Late static bindings doesn't have anything to do with your case, late static binding is simply a way of referencing things. The problem here is the dynamic creation of static properties, which was rejected multiple times.

If you want to store metadata in a static property, you can always use an array with the classnames as indices: self::$_metadata[get_called_class()] = ...
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 06:01:28 2024 UTC