php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30642 static variables not inherited by other classes when extended
Submitted: 2004-11-01 04:53 UTC Modified: 2004-11-19 17:34 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: keith dot ward at gmail dot com Assigned: helly (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: keith dot ward at gmail dot com
New email:
PHP Version: OS:

 

 [2004-11-01 04:53 UTC] keith dot ward at gmail dot com
Description:
------------
When using extend to extend a class . Static variables are not  inherited .

Reproduce code:
---------------
class a
{
        public static $myvar;
        public function __construct()
        {
                $this->myvar = '1';
                echo ' Set myvar to 1 ... ' . "\n";
                var_dump($this);
        }
}

$a =  new a();
class b extends a
{
        function __construct()
        {
                echo 'DUmping from class b' . "\n";
                var_dump($this);
        }
}
$a = new b();
?>

Expected result:
----------------
 Set myvar to 1 ... 
object(a)#1 (1) {
  ["myvar"]=>
  string(1) "1"
}
Dumping from class b
object(b)#2 (1) {
  ["myvar"]=>
  string(1) "1"
}


Actual result:
--------------
 Set myvar to 1 ... 
object(a)#1 (1) {
  ["myvar"]=>
  string(1) "1"
}
Dumping from class b
object(b)#2 (0) {
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-01 11:51 UTC] helly@php.net
var_dump() doesn't show static members.

And don't reopen this report - check your code
 [2004-11-02 01:52 UTC] keith dot ward at gmail dot com
This is NOT BOGUS , had you bothered to read the results , you would see that var_dump , did indeed return the static member myvar( from class A )  . 
If returning static members with var_dump was not to be supported (that's what it sounds like) it should not show up in the first var_dump either !.
In Addition ... using echo parent::$myvar;  or echo $this->myvar within class B , also returns nothing . So this bug is perfectly valid .
 [2004-11-03 17:34 UTC] ashk06 at dsl dot pipex dot com
http://bugs.php.net/bug.php?id=30451

Seems to be a duplicate of this .
 [2004-11-19 17:34 UTC] tony2001@php.net
Nope, #30451 has nothing to do with it.
And yes, var_dump() DOES NOT show static members (see #30820, this issue is correctly reported there).

I'm closing this report, as there is no sense in keeping duplicates.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 14:01:29 2024 UTC