php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44315 Late static binding not working for variables
Submitted: 2008-03-03 01:18 UTC Modified: 2008-03-03 01:46 UTC
From: m dot kurzyna at crystalpoint dot pl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-03-03 (snap) OS: PLD Linux
Private report: No CVE-ID: None
 [2008-03-03 01:18 UTC] m dot kurzyna at crystalpoint dot pl
Description:
------------
Late static binding doesn't seem to apply to static class variables. 
Example is rather self explanatory (construtor using static keyword 
should increment variable in calling class).

Reproduce code:
---------------
<?php
	class B {
		static protected $counter = 0;
		
		public function __construct() {
			++static::$counter;
			var_dump(static::$counter);
		}
	}

	class C extends B {
		public function __construct() {
			++static::$counter;
			var_dump(static::$counter);
		}
	}

	new B;
	new C;
?>

Expected result:
----------------
int(1)
int(1)

Actual result:
--------------
int(1)
int(2)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-03 01:31 UTC] m dot kurzyna at crystalpoint dot pl
The snapshot used was php-5.3-2008-03-02-21:30.
 [2008-03-03 01:38 UTC] colder@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

in C::__construct, static resolves to C, and C::$counter is not defined per-se, a fallback occurs and B::$counter is incremented. Nothing to do with late static bindings.
 [2008-03-03 01:46 UTC] m dot kurzyna at crystalpoint dot pl
Hm.. ok. My bad. Thanks for the extra info.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 10:01:28 2024 UTC