Login to Your Account


Login using your Facebook account

Join the Mercury Community

Click on all the boats to prove you're human.


How To Home | more...

Function Naming Conventions

With the exception of a few core functions, all Mercury functions follow a strict naming convention.  The convention will be explained and will be followed by the rationale.

Naming Convention

For a module called foo and a function called bar then the function will live in one of two places: html/mercury/foo/functions/bar.php or in the core mercury/foo/functions/bar.php.  The actual function itself will be called foo__bar and will take the following syntax:

    <?php
        function foo__bar($in){
            // code here
        }
    ?>

where $in is an optional variable and, if passed, will be a single variable or an array.

All functions in a given module will start with modulename followed by two underscores (ie: modulename__)

Why do such a crazy thing?

To accomplish our goal of efficiency we only load the functions that we actually use.  Since it might make sense for functions in two different modules to have the same working name we need to ensure that each actual function name is unique in the Mercury namespace.  The logical direction was to make a file with the working name of the function and to have an actual function name that is uniquely identified by both the module name and the function name.

The file is loaded into memory when it is first requested within a page request.  It is then executed. Upon subsequent calls to the same function Mercury knows that the file is already loaded and simply executes it.  Load times are decreased since we only ever load what we use.