1

I am new to PHP and has started with Moodle. In Moodle I found that there is a global object $DB, instance of moodle_database class. I found that moodle_database is an abstract class. And various functions of moodle_database are abstract as well.

global $DB;
$DB = new moodle_database();

And moodle_database:

abstract class moodle_database

How is it possible to create an instance of abstract class? Even if moodle_database was extended by some other class and $DB was an object of that class, things can be assumed to be simple.

1 Answer 1

1

In lib/setup.php, there is a call to setup_DB(), which is defined in lib/dmllib.php.

This, in turn, calls $DB = moodle_database::get_driver_instance() which instantiates a subclass of moodle_database.

I don't know exactly where the line of code you refer to its found, but I suspect that it will never actually be run and is simply there to provide type hinting to IDEs, so auto completion will work when writing moodle code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.