Can I instantiate a PHP class inside another class?

You can’t define a class in another class. You should include files with other classes outside of the class. In your case, that will give you two top-level classes db and some. Now in the constructor of some you can decide to create an instance of db. For example:

include SITE_ROOT . 'applicatie/' . 'db.class.php';

class some {

    public function __construct() {
        if (...) {
            $this->db = new db;
        }
    }

}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)