Difference Between StudlyCaps and camelCase in PHP

Quick Summary

  • StudlyCaps, also called PascalCase, capitalizes the first letter too (OrderManager), while camelCase keeps it lowercase (getOrderTotal).
  • PSR-1 requires StudlyCaps for class names, camelCase for method names and upper case with underscores for class constants, and sets no rule for properties.
  • WordPress uses its own style instead: lowercase words with underscores for functions and methods, as in get_the_title(), and Capitalized_Words for classes, as in WP_Query.

StudlyCaps and camelCase both write several words as one, without spaces, and start each new word with a capital letter. The difference is the first letter: StudlyCaps capitalizes it too (OrderManager), while camelCase keeps it lowercase (getOrderTotal). In PHP, the PSR-1 coding standard uses StudlyCaps for class names and camelCase for method names. StudlyCaps is the same thing as PascalCase.

What does PSR-1 say about naming?

PSR-1, the basic coding standard of the PHP Framework Interop Group (PHP-FIG), sets these naming rules:

  1. Class names MUST be declared in StudlyCaps.
  2. Class constants MUST be declared in all upper case with underscore separators, such as MAX_ITEMS.
  3. Method names MUST be declared in camelCase.

A class that follows these rules, with the brace placement and constant visibility that PSR-12 and its successor, PER Coding Style, add:

PHP
class OrderManager
{
    public const MAX_ITEMS = 10;

    public function getOrderTotal(): int
    {
        return 42;
    }
}

PSR-1 deliberately makes no rule for property names: $StudlyCaps, $camelCase and $under_score are all allowed, as long as you use one style consistently within a vendor, package, class or method. It doesn’t cover plain functions or local variables either.

Is StudlyCaps the same as PascalCase?

Yes. Both names describe the style where every word, including the first, starts with a capital letter. PSR-1 uses the term StudlyCaps without defining it, and PER Coding Style, which replaces PSR-12, settles it: “The term ‘StudlyCaps’ in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter.” PER also requires PascalCase for enum cases.

Does PHP itself care?

No. Class, function and method names are case-insensitive in PHP, so new ordermanager() and ->GETORDERTOTAL() work on the class above. Variable names and constants are case-sensitive: $orderTotal and $ordertotal are two different variables. The conventions exist for the people reading the code and the tools that check it.

Case does matter for autoloading. PSR-4 requires the file name to match the case of the class name, so OrderManager lives in OrderManager.php.

Does WordPress use camelCase?

No. The WordPress PHP coding standards use lowercase words separated by underscores for functions, variables and hook names, as in get_the_title(), and capitalized words separated by underscores for class names, as in WP_Query. Core methods follow the lowercase style too, such as WP_Query::have_posts(). Class files are named after the class with class- in front: WP_Error lives in class-wp-error.php.

The same class in WordPress style:

PHP
class Order_Manager {
    const MAX_ITEMS = 10;

    public function get_order_total() {
        return 42;
    }
}

Use the WordPress style in themes and plugins, so your code reads like the core functions it calls, and the PSR style in packages meant for the wider PHP ecosystem.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More