Based upon the name itself, countModules, we can guess that this function will return the number of active modules in the given position. It is easy to test this theory, which we will do below.

How many active modules do we have in each position?

If you look at the code above, you will see that we are testing three different positions:

position-3

position-6

position-8

When we log into our Joomla Administrator section, we can go to Extensions » Module Manager to confirm how many modules we have in each position. Review the screenshots below:

position-3

position-6

As you can see in the screenshot, we currently have 2 modules active in position-3.

The above screenshot shows that we have 3 modules in position-6, but only 1 is active.

Because we didn't have any modules in position-8, we didn't have an option to filter modules by position-8.

What value does countModules return?

Now that we know how many modules are in each of these positions, we can test the countModules function to see what it actually returns. Here's the code we are using to test the output of the function:

If you look to the right, you'll see a screenshot of the results. As you can see, the return value of each countModules call returns the total number of modules active (which does not include disabled modules in that position).