如何在类的方法中引用include进来的文件中的变量?

include 'db_link.php';

class Search
{

private $S_id;
private $D_id;
private $range;

public function setS_id($S_id){
    $this->S_id = $S_id;
}

public function get_Sid(){
    return $this->S_id;
}

public function setD_id($D_id){
    $this->D_id = $D_id;
}

public function getD_id(){
    return $this->D_id;
}

public function checkPerson($S_name){
    
}

在方法checkPerson()中如何访问'db_link.php'的变量?
慕标5832272
浏览 546回答 3
3回答

慕仙森

我都是这样的: class A{ public $db; public function __construct(){ include 'db_link.php'; $this->db = $arg_from_db_link; } }

泛舟湖上清波郎朗

a.php $a = 111; return $a; b.php $c = include 'a.php'; echo $c;
打开App,查看更多内容
随时随地看视频慕课网APP