#47384 [Opn]: static references resolved incorrectly with class inheritance

From: Date: Mon, 23 Nov 2009 14:54:31 +0000
Subject: #47384 [Opn]: static references resolved incorrectly with class inheritance
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3316@lists.php.net to get a copy of this message
 ID:               47384
 Updated by:       vrana@php.net
 Reported By:      alreece45 at gmail dot com
 Status:           Open
 Bug Type:         Documentation problem
 Operating System: *
 PHP Version:      5.*, 6
 New Comment:

If the variable is initialized in the constructor then it gives the
expected output:

function __construct() {
	$this->name = self::my_name;
}

So this is specific to initialization in the declaration.


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

[2009-11-20 13:40:24] alreece45 at gmail dot com

Again, this is NOT the difference between self and static, this is the

self keyword behaving like static when it shouldn't.

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

[2009-11-20 10:01:01] vrana@php.net

Difference between self:: and static:: is already documented.

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

[2009-06-15 14:57:35] alreece45 at gmail dot com

In the example self is behaving as static does. It should not be doing
that. It contradicts the documentation.

In the father class: $name is set as self::my_name, which is "Father".
In the child classes, even though $name is not set, it goes to
Son::my_name and GrandSon::my_name.

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

[2009-06-14 23:09:24] scottmac@php.net

You can use static:: in PHP 5.3+ this is Late Static Binding.

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

[2009-06-14 13:51:01] alreece45 at gmail dot com

Perhaps this is not a Documentation Problem, but a scripting problem? I
set it as documentation because I wasn't sure if this behavior was
intentional or not. If it was intentional, the documentation needed to
be updated because it currently says:

"Static references to the current class like self:: or __CLASS__ are
resolved using the class in which the function belongs, as in where it
was defined"

I'd appreciate it to know, at the very least, if this behavior is
intentional or not for two reasons:
1) Avoid using the "feature" in PHP projects.
2) So I know if I take the time to try make a patch: I know I didn't
just waste my time (even if I fail).

also: updating the summary to be more clear (hopefully)

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/47384

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



Thread (8 messages)

« previous php.doc.bugs (#3316) next »