Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active November 1, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotherightthing/57c89eea979d34c929d8b9cd32606898 to your computer and use it in GitHub Desktop.
Save dotherightthing/57c89eea979d34c929d8b9cd32606898 to your computer and use it in GitHub Desktop.
[Autoloading and Namespaces] Namespacing prevents classes from leaking into the global scope. #php #wordpress #dev

Autoloading and Namespaces

composer.json

This object instructs Composer to automatically require PHP files inside src, which use the namespace WPDTRT_Plugin:

"autoload": {
  "psr-4": {
    "DoTheRightThing\WPPlugin\\": "src/"
  }
}

src/Shortcode.php


Scope

// Package namespace
DoTheRightThing\WPPlugin\Shortcode
// Global namespace
\Gamajo_Template_Loader
@dotherightthing
Copy link
Author

namespacing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment