0
<?php
class X {
function foo() {
echo "Class Name:".get_class($this)."<br>"; //it displays Y... :)
echo get_class($this)::$public_var; //not working
echo Y::$public_var; //works
Y::y_method(); //works
get_class($this)::y_method(); //not working
$classname = get_class($this);
$classname::y_method(); // again not working.. :(
}
function bar() {
$this->foo();
}
}
class Y extends X {
public static $public_var = "Variable of Y Class";
public function y_method()
{
echo "Y class method";
}
}
$y = new Y();
$y->bar();
?>
my only question is how to get access members of y class only with dynamically providing class name without changing current structure.
を探しています..だから質問は何ですか? – binaryLV
get_class()は常にXを返します。$これは静的関数では設定されていません。エラーを有効にし、ログを読んで学習します。代わりに 'get_called_class()'を探しているかもしれません。 – hakre
の可能な複製[親静的関数から静的子関数をどのように呼び出すのですか?](http://stackoverflow.com/questions/6678466/how-do-i-call-a-static-child-function-from-親静的関数) – hakre