小编Md *_*iam的帖子

php中扩展一个类和在另一个类中创建实例的区别

第一个文件:

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 会发生什么?有什么区别吗?

php oop instantiation

5
推荐指数
1
解决办法
169
查看次数

标签 统计

instantiation ×1

oop ×1

php ×1