Using PHP Namespaces and Libraries

Applies to: Jamroom 7.0+ Last verified: 2026-10-24

Table of Contents:


Third-party libraries
Namespaces
  • Third-party libraries

    Put a library in your module, for example in lib/ or contrib/, and load it where you use it, not in _init(): _init() runs on every request.

    function xxFoo_get_client()
    {
        require_once APP_DIR . '/modules/xxFoo/contrib/vendor/autoload.php';
        return new \Vendor\Package\Client();
    }
  • Namespaces

    Module files aren't namespaced: Jamroom calls module functions by name. Refer to namespaced classes by their full name, as above, or with a use statement at the top of the file that uses them:

    <?php
    defined('APP_DIR') or exit();
    
    use Vendor\Package\Client;

Tags