//依赖注入是应用于一个类的实例化需要依赖另外一个类的场景
//Person依赖于Student类,Student类注入到Person
class Person{
public function teach($obj){
return $obj->study();
}
}
class Student{
public function study(){
return 123;
}
}
public function personTest(){
$p = new Person();
$s = new Student();
echo $p->teach($s);
}
原文:https://www.cnblogs.com/lkl6/p/13577399.html