php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42681 Static variables in sub/superclasses
Submitted: 2007-09-16 03:36 UTC Modified: 2007-12-06 13:47 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: alex94040 at yahoo dot com Assigned: helly
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4 OS: *
Private report: No CVE-ID:
 [2007-09-16 03:36 UTC] alex94040 at yahoo dot com
Description:
------------
This is a reactivation of bug 28442; that bug shows as "fixed/closed", but the issue still repros. 

We need to be able to redefine static members of classes (including constants), and set them independently.

Reproduce code:
---------------
class ClassA
{
   private  static   $cn;

   public static function setName( $cn )
   {
      self::$cn   = $cn;
   }

   public static function  getName( )
   {
      return self::$cn;
   }
}

class ClassB extends ClassA
{
   private  static   $cn; // with or without this, result is the same
}

ClassA::setName( 'AAA' );
ClassB::setName( 'BBB' );

print( ClassA::getName() . "\n" ); // prints 'BBB'
print( ClassB::getName() . "\n" ); // prints 'BBB'


Expected result:
----------------
Result should read "AAA BBB"

Actual result:
--------------
Result actually reads "BBB BBB"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-18 10:44 UTC] jani@php.net
Marcus, can you reply to this please?
 [2007-12-06 13:47 UTC] helly@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

This is different from 28442. In fact the static variables are different here as 28442 proves. However you are only using one of them. You need to wait for LSB to make it into PHP and use the new syntax then. This will most likely be solved in 5.3.0.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 25 07:02:14 2014 UTC