|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-30 17:33 UTC] flyguy dot by at gmail dot com
Description:
------------
This is code prints "test2". Why ?
Test script:
---------------
class test1 {
public static function testing_method() {
var_dump(get_called_class());
}
}
class test2 {
public static function testing_method() {
parent::testing_method();
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 13 00:00:01 2025 UTC |
Etienne, you are the LSB expert - what's your take on this? - In the given example I can see the reporter's point. (While there is a "extends test1" missing) I wonder about this: class test1 { public static function testing_method() { var_dump(get_called_class()); } } class test2 extends test1 { } class test3 extends test2 { public static function testing_method() { parent::testing_method(); } } Here parent might refer to test2, test2 inherits testing_method() from test1 so the called class might be test2 ... some might argue that test1 is correct. I think the most simple thing is to keep the current behavior and define parent not to change the lsb scope.Ok. This situation is analogous to the one hand, but why then: class my_parent { public static $field; public static function field_setup() { static::$field='asd'; } } class my_child extends my_parent { } my_child::field_setup(); var_dump(my_child::$field); var_dump(my_parent::$field); ---------- prints: string 'asd' (length=3) string 'asd' (length=3)class my_parent { public static $blabla='asd'; public static function set_blabla($val) { static::$blabla=$val; } } class my_child extends my_parent { } my_child::set_blabla('qwerty'); var_dump(my_child::$blabla); var_dump(my_parent::$blabla); -------- prints: string 'qwerty' (length=6) string 'qwerty' (length=6) ---- This is normal code too ? Why changed extended propety on parent ? By your logic inherited properties are not inherited properties. Simply class-parent becomes part of the subclass.