php.net |  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
Votes:2
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
Description:
------------
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:
---------------
<?php

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";
C::foo();
echo P::$v . "\n";

// RESULTS
parent
child
child




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

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-17 19:24 UTC] colder@php.net
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: Thu Mar 28 22:01:26 2024 UTC