Inheriting static methods/properties
Posted: Tue Jun 05, 2007 6:13 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I've read the discussion on this, but I just think it's wrong. In the example below, the only you'll see "bar" is if both commented sections are uncommented, which keeps the context completely in class b. I understand the reasoning behind the behavior. At the same time, this behavior ignores the concept of reusability. I'd have to reproduce all of my class a code in class b for 'proper' behavior, which negates the reason for having class a to begin with. Is there any reconciliation for this? Last I heard, "this behavior is expected and will not be fixed"...Code: Select all
<?
class a {
protected static $var1 = "foo";
protected static function doit() {
echo("in a:doit = " . self::$var1) . "<br>";
}
public function go() {
self::doit();
}
}
class b extends a {
protected static $var1 = "bar";
/*
// commented section 1
protected static function doit() {
echo("in b:doit = " . self::$var1);
}
*/
/*
// commented section 2
public function go() {
self::doit();
}
*/
}
$d = New a;
$e = New b;
$d->go();
$e->go();
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]