From:             matt at c dot anvas dot es
Operating system: Any
PHP version:      5.1.4
PHP Bug Type:     Class/Object related
Bug description:  Incorrect Inheretence Context

Description:
------------
Though I've verified that others have noted the same problem 
with code similar to mine, I noticed what appeared to be a 
greater problem than at first realized.

In the code below, a call to get_class() from a static 
method inhereted from the parent class actually shows no 
evidence of inheretence. One look at the stacktrace and 
you'll not even see one mention of the child class.

Late static binding may fix this, as I'm not precisely sure 
what that does and what the exact problem is, but the way I 
see it, the child class is not inhereting everything from 
its parent but has, instead, thrown the call to its parent, 
thereby changing its context.

Again, consider the code: my context is that I'm talking 
with a child object, whose parent has a static method that 
gets its name. Unfortunately, when asking the child its 
name, the parent's name is instead given. If indeed the 
child has inhereted its parents properties and methods, then 
this is a bug whereby it changes the context outside of 
itself.

Compare this to human inheretence and the children inheret 
all of the properties from their parents (though a bit 
organically with crossing over and the like). But still, it 
contains those things and does not go to the parent every 
time a property or an action needs to be consulted or acted.

Again, a look at the backtrace reveals that it totally skips 
the child class, as if it doesn't even exist.

Reproduce code:
---------------
class Parent {
  public static function name() {
    // debug_print_backtrace(); // observe this
    return get_class();
  }
}

class Child extends Parent {}

print Child::name();

Expected result:
----------------
Child

Actual result:
--------------
Parent

-- 
Edit bug report at http://bugs.php.net/?id=37723&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=37723&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=37723&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=37723&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=37723&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=37723&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=37723&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=37723&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=37723&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=37723&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=37723&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=37723&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=37723&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=37723&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=37723&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=37723&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=37723&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=37723&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=37723&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=37723&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=37723&r=mysqlcfg

Reply via email to