php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30140 Problem with array in static properties
Submitted: 2004-09-18 17:02 UTC Modified: 2005-06-08 15:22 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (25.0%)
From: guth at fiifo dot u-psud dot fr Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-05-07 OS: *
Private report: No CVE-ID: None
 [2004-09-18 17:02 UTC] guth at fiifo dot u-psud dot fr
Description:
------------
[ sorry for english ] 
 
There is a problem with static properties initialized as 
an array in classes. 
 
In the following code, if you replace "public static $test 
= array();" by "public static $test;" or if you initialize 
the property with not an array ("public static $test = 
12;" for example), it works as expected. 

Reproduce code:
---------------
<?
class A {

	public static $test = array();

	public function set($var) {
		self::$test = $var;
	}

	public static function view() {
		var_dump(self::$test);
	}

}

class B extends A {

	public static function view() {
		var_dump(self::$test);
	}

}

$class = new B;
$class->set(array('key' => 'value'));

A::view();
B::view();
?>

Expected result:
----------------
array(1) { ["key"]=> string(5) "value" } 
array(1) { ["key"]=> string(5) "value" } 

Actual result:
--------------
array(1) { ["key"]=> string(5) "value" } 
array(0) { } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-05 23:24 UTC] tony2001@php.net
Yet another duplicate of bug #30934.
 [2005-05-09 11:34 UTC] sniper@php.net
This same thing happens with boolean too. All other types behave correctly (or incorrectly, not sure anymore :)

Andi, (or Dmitry maybe?) can you look into this?

 [2005-05-17 16:27 UTC] stas@php.net
It's definitely duplicate for bug #30934.
 [2005-06-08 11:18 UTC] dmitry@php.net
No this is another bug. The problem is in zval_update_constant().

Reproduce code:
---------------
<?php
class A {
	public static $test1 = true;
	public static $test2 = array();
	public static $test3 = "str";
}

class B extends A {
}

A::$test1 = "x";
A::$test2 = "y";
A::$test3 = "z";
var_dump(A::$test1);
var_dump(A::$test2);
var_dump(A::$test3);
var_dump(B::$test1);
var_dump(B::$test2);
var_dump(B::$test3);
?>

Expected result:
----------------
string(1) "x"
string(1) "y"
string(1) "z"
string(1) "x"
string(1) "y"
string(1) "z"

Actual result:
--------------
string(1) "x"
string(1) "y"
string(1) "z"
bool(true)
array(0) {
}
string(1) "z"


 [2005-06-08 15:22 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC