Static method inside another class
<p>I have a class name DBConnection:</p>

<pre><code>   class DBConnection {

    public function __construct() {}
    public static function getConnection() {
        try{
            $conn = new PDO('mysql:host='.HOST.'; dbname='.DATABASENAME.'; charset=utf8', USERNAME, PASSWORD);
            return $conn;
        }catch(PDOException $e){
            echo("Connect to database failed");
        }

    }

}
</code></pre>

<p>And a class name bookDA:</p>

<pre><code>require_once("DBConnection.php");
require_once("../entity/book.php");
class bookDA {

    private $conn = DBConnection::getConnection();//This line didn't work

    public function getAll() {
        $bookList = array();
        $stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM booklist");
        $stmt-&gt;execute();
        while($result = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
            $bookList[] = new book($result["bookId"], $result["bookName"], $result["bookPrice"]);
        }
        return bookList;
    }
    public function getByName($name) {
        $bookList = array();
        $stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM booklist WHERE LIKE :name");
        $stmt-&gt;bindValue(":name", "%".$name."%", PDO::PARAM_STR);
        $stmt-&gt;execute();
        while($result = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
            $bookList[] = new book($result["bookId"], $result["bookName"], $result["bookPrice"]);
        }
        return bookList;
    }

}
</code></pre>

<p>i create a static method:"getConnection" inside class DBConnection, and in the class:"bookDA" i call it but it didn't work. So i try to put the line which didn't work outside the bookDA class and this work like a champ. Can anyone tell me why?</p>