第一个文件:
class Class_one {
public function __construct() {
}
public function show_name() {
echo "My Name is Siam";
}
public function show_class() {
echo "I read in class 7";
}
}
Run Code Online (Sandbox Code Playgroud)
第二个文件:
<?php
require_once './Class_one.php';
class Class_two {
public $class_one;
public function __construct() {
$aa = new Class_one();
$this->class_one = $aa;
}
public function history() {
$this->class_one->show_name();
}
}
$ab = new Class_two();
$ab->history();
Run Code Online (Sandbox Code Playgroud)
如果我不在 class_two 中实例化 class_one 并将 class_one 扩展到 class_two 会发生什么?有什么区别吗?