Autoloading Local PHP Classes: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "== Objective == Have a mechanism in place to autoload classes to avoid having to place `require_once()` calls throughout the app's files. == Prerequisites == Composer ==...")
 
(No difference)

Latest revision as of 23:53, 4 September 2019

Objective[edit]

Have a mechanism in place to autoload classes to avoid having to place require_once() calls throughout the app's files.

Prerequisites[edit]

Composer

Edit composer.json to autoload local classes[edit]

Add the following directive to composer.json:

{
  "autoload": {
    "classmap": [
      "Classes/"
    ]
  }
}

Update Composer's autoloader with php composer.phar dumpautoload from the project root directory. [1]

Notes[edit]