Answer the question
In order to leave comments, you need to log in
How to get the name of a subclass?
Hello. Tell me how you can assign a string to the $now property of the Chief class - the name of the subclass (A or B or C) in which an undefined property is currently called . That is, how can the Chief class know the names of its subclasses in which an undefined property is called.
error_reporting(E_ALL);
class Chief
{
public $now;
public function __get($name){
return $name;
}
}
class A extends Chief
{
public function perf(){
return $this->pr_a;
}
}
class B extends Chief
{
public function perf(){
return $this->pr_b;
}
}
class C extends Chief
{
public function perf(){
return $this->pr_c;
}
}
class Closing extends Chief
{
public $all = array('A','B','C');
public function perf(){
foreach($this->all as $v){
$aught = new $v;
echo $aught->perf().'<br>';
}
}
}
$res = new Closing();
print $res->perf();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question