1
다른 클래스에서 참조해야하는 $ 데이터베이스 객체가 있습니다.
이것이 올바른 방법일까요?클래스에 대한 참조 전달
<?php
class User {
private $database;
function getPosts($limit = 1) {
return $this->database->query("select...");
}
function __construct(&$database) {
$this->database = $database; // Do I need an another ampersand here?
}
}
$user = new User($database); // $database is defined in an earlier include
?>
멋지다. 나는 확실하지 않았다. 감사 – arby