MODX PHP Coding Standards


  • Beginning brackets do NOT linebreak. They start one space after the end parenthesis, as according to traditional Unix policy.
  • Do not do any real logic in object constructors. Create class methods to do so.
    null, true and false should always be lowercase.
  • Avoid embedded assignments (ex: $d = ($a = $b + $c) is bad).
  • Never use extract().
  • Avoid using global variables if at all possible.
  • Document EVERYTHING.


  • Do not put parenthesis next to keywords. Put a space between.
  • Do put parenthesis next to function names.
  • Do not use parenthesis in return statements when it's not necessary. Example:
    if ($test) {
    while ($test == $other) {
    return $test;
  • Do not use parenthesis when using include, require, include_once, and require_once.


  • All ''core'' classnames, unless stated otherwise for special conditions, will be prefixed with the "mod" prefix: ie, modChunk, modTemplate, etc.
  • All method names will be camelCase and will start with a lowercase letter.
  • All private methods and variables must be prefixed with the underscore _ character.
    class modFactor {
        public $publicVar;
        private $_privateVar;
        private function _privateFunc() { }
        public function publicFunc() { }


Note these are not function arguments.

  • Use all lowercase letters.
  • Separate words with the underscore.

Function Arguments and Class Variables

  • The first letter is lowercase, rest are camelCase. Example:
    class modFactor {
        public function testFunc($testVar, array &$anotherTest = array()) {
            $this->_privateVar = $testVar;
            $local_variable =& $anotherTest;


  • Array index names use the underscore _, not the dash as their separator. This prevents errors with magic_quotes.
  • Array index names are always lowercase. Spaces are represented by an underscore.
  • Array index names are always encapsulated with single quotes.
    $_lang['chunk_create_text'] = 'Test';


  • Constants must be in all UPPERCASE letters.
  • Use only if absolutely necessary.

File Structure

  • Always name PHP class files in name.class.php format.


  • Lexicon strings for Components need to be prefixed:
$_lang['mycomponent.welcome_message'] = 'Welcome!';
  • Always prefix class names; eg: 'finBank', 'finTransaction', etc.
  • Always prefix Chunk names; eg: 'finStatement', 'finDeposit'

Comment Policy

These comments are not for usage questions or support. See below for support options.

Comments intended add specific value for other users with this document are welcome! Have a suggestion to improve this document? Suggest an edit (requires GitHub account). Have suggestions for code changes or feature requests? .

Support Options

If you need assistance, you can get it via the MODX Forums or the MODX Community Slack.

Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab) or become an editor of the MODX Documentation.