php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37723 Incorrect Inheretence Context
Submitted: 2006-06-07 07:34 UTC Modified: 2006-06-09 07:20 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: matt at c dot anvas dot es Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2006-06-07 07:34 UTC] matt at c dot anvas dot es
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-07 08:04 UTC] matt at c dot anvas dot es
(Fixed name)
 [2006-06-07 08:05 UTC] tony2001@php.net
Try to search bug DB before reporting new issues.
See bug #37654 and bug #37684.
 [2006-06-07 21:02 UTC] matt at c dot anvas dot es
I did search, and I see something beyond 'late static 
binding' here. The child class (or the parser) is leaving 
its context in search of the method to inheret, but it 
doesn't bring it into its context. In fact, it takes the 
user into the parent's context. It changes its context.

This goes beyond simply saying that you're trying to figure 
out how to do 'late static binding', and more into the realm 
of 'hey, this is a bug, because the child class should 
inheret its parents innards, and _stay within its context_.'

Am I mistaken in this thought? Is is perfectly OK and not a 
bug that the context itself is changed?

I submitted this bug because I don't think the previous bug 
submissions adequately described the issue at hand. Please 
read the description.

M.T.
 [2006-06-07 22:02 UTC] tony2001@php.net
>hey, this is a bug, because the child class should 
>inheret its parents innards'
That's EXACTLY what it does and I personally consider this expected. The child inherits parents context, what's wrong here?
But we're working on late static binding, which would change this behaviour to the expected one, that's why there is no sense in keeping this report open.
Thank you.
 [2006-06-07 22:32 UTC] matt at c dot anvas dot es
The fact that it ignores the child class if it doesn't 
define a matching static method and instead changes its 
context to that of the parent is expected? How does that 
make sense if it inherits the parent class? If it does, 
indeed, inherit the parent class, it will have the static 
method, not having to go to the parent and ignore the 
child's existence.

I understand that finding methods and the like from parents 
can be tricky, having to navigate the inheritence tree, but 
it's unexpected to suddenly become the parent class when 
you're working with the child class.

I may not sway you to keep this open as an actual bug (as I 
see it), but your answers will at least teach me, if nothing 
else, the mindset of the core developers et al.

I'd like to know if late static binding is considered a 
feature or a bug fix. If it is a bug fix, then you're right: 
this bug report is just a duplicate. However, if the late 
static binding really is just a feature to cover this up, I 
see a potential problem. I'd like to know, really, if this 
is considered a bug or a mere inconvenience.

M.T.
 [2006-06-09 05:21 UTC] matt at c dot anvas dot es
See previous comment
 [2006-06-09 07:20 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

Static methods are bound at compile time. At compile time function name resides in Parent. Thats it - perfectly correct.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC