php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64337 Static properties overwritten by children
Submitted: 2013-03-02 13:02 UTC Modified: 2013-03-02 14:42 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: nat at nath dot is Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: OSX
Private report: No CVE-ID: None
 [2013-03-02 13:02 UTC] nat at nath dot is
Description:
------------
If you extend a class, which has a static property, and set that static property, 
it will overwrite the variable in the parent, not in the child. 

Test script:
---------------
<?php

class One {
	
	public static $var = 'hi';
}

class Two extends One {
	
	public static function set($var) {
		static::$var = $var;
	}
}

Two::set('bye');

var_dump(One::$var);

Expected result:
----------------
"hi"

Actual result:
--------------
"bye"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-02 14:42 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

if you want a new copy of static variable in sub-class => redeclare it.

not bug here.
 [2013-03-02 14:42 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 03:01:33 2024 UTC