ID:               49105
 Comment by:       mail at dropdev dot org
 Reported By:      atrauzzi at gmail dot com
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Linux
 PHP Version:      5.3.0
 New Comment:

You're confusing two similar, yet different concepts, Inheritance and
Extension.

Also, PHP is doing it perfect, since you actually inherit a static
variable (that all point to the same memory point.)

think of this example:
<?php
abstract class MasterAlarm {

  protected static $state = "";

     public static function alert() {
         static::$state = "ALERT";
     }

     public static function safe() {
         static::$state = "safe";
     }

     public static function showMasterAlarmState() {
         return(static::$state);
     }

}
?>
and then extend it:
<?php
class Bell extends MasterAlarm {
}

class Button extends MasterAlarm {
}
?>
and the executing code
<?php
Light::safe();
Light::showMasterAlarmState();   // "safe"

Button::alert();
Button::showMasterAlarmState();  // "ALERT"
Light::showMasterAlarmState();   // "ALERT"

Button::safe();
Light::showMasterAlarmState();   // "safe"
?>


Previous Comments:
------------------------------------------------------------------------

[2009-07-30 00:42:01] atrauzzi at gmail dot com

Description:
------------
Subclass properties should be duplicated from the parent class, not
passed through to the parent class.

The current behaviour is redundant and possibly misleading.  Especially
with the great selection of scopes in PHP (parent::, static::, self::).

The current workaround is to dump everything into an array on the
parent, keyed by subclass.  This knocks out cohesive design and
restricts the potential for some fairly neat designs.

At the very least - to prevent accidental misuse - a subclass should be
throwing an error when trying to access a property that doesn't exist,
but does exist on a parent.
Really what should be happening though, is a child should be getting
its own copy of each property defined in the parent.

Reproduce code:
---------------
abstract class Parent {
  protected static $message = "UNTOUCHED";
     public static function yeah() {
         static::$message = "YEAH";
     }
     public static function nope() {
         static::$message = "NOPE";
     }
     public static function lateStaticDebug() {
         return(static::$message);
     }
}

class Child extends Parent {
}

Expected result:
----------------
Parent::yeah();
Parent::lateStaticDebug();  // Return "YEAH"

Child::nope();
Child::lateStaticDebug();  // Return "NOPE"

Parent::yeah();
Child::lateStaticDebug()   // Return "NOPE"

Actual result:
--------------
Parent::yeah();
Parent::lateStaticDebug();  // Returns "YEAH"

Child::nope();
Child::lateStaticDebug();  // Returns "NOPE"

Parent::yeah();
Child::lateStaticDebug()   // Returns "YEAH"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49105&edit=1

Reply via email to