php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30235 Inheritance of private static variables fails (related to self:: )
Submitted: 2004-09-25 23:45 UTC Modified: 2004-09-26 20:34 UTC
From: kell_pt at users dot sf dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-09-25 (dev) OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kell_pt at users dot sf dot net
New email:
PHP Version: OS:

 

 [2004-09-25 23:45 UTC] kell_pt at users dot sf dot net
Description:
------------
The issue is pretty simple I've explained this problem before, I'm unsure why it hasn't been addressed - it's a design flaw and violates basic principles of what you'd expect from an OOP language.

Consider a static function in a base class, and a class that inherits from the above. In such a static function, self:: always refers to the class where the code was declared. That is wrong, it should be relative to the class the code was called from. It makes it impossible to have seperate variables in sub-classes sharing the same code.

It is easier watching the example, it speaks for itself. When "test()" runs, on the second call, it should be running within context of ClassB, not ClassA.

This is related to bug #28442, which was apparently ignored. Can someone at least explain what is the reasoning behind it working like that? I don't want to sound rude, but I know how it works, the distinctions between public and private, please don't patronize me (again). :)

Reproduce code:
---------------
class ClassA
{
   private static $base    = "Variable from ClassA";
   static function   test()
   {
      print( self::$base . "\n" );
   }
}

class ClassB extends ClassA
{
   private static $base = "Variable from ClassB";
}

ClassA::test();
ClassB::test();


Expected result:
----------------
Variable from ClassA
Variable from ClassB

Actual result:
--------------
Variable from ClassA
Variable from ClassA

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-26 20:34 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

Sorry, you have a complete wrong idea og OO programming.

Static methods are bound/resolved at compile time. That is the compiler can replace self with the current class.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC