I recently started working extensively with Magento and Code sniffer, and I would like to know which standards I should follow.

I tried Zend coding standards, but I don't want to use the 80 line limit, and it's not used in the core either.

After that, I tried CS2 standards, but that doesn't work either because of the _ in various functions, and class names, which have an _ in them, and don't have namespaces.

So, is there another standard that the core code complies 100% with ? If not, shouldn't magento have its own coding standards? It has its own stackexchange site, some well defined coding standards would be welcome to be used by extension developers.

5 Answers 5


You can also try ECG Magento Code Sniffer Coding Standard


Magento best practices are quite good described by Josh Pratt here. He suggests to adopt and follow the Zend Code Style Standards and I can only join him.

The maximal line length is not a strict requirement. However from readability point of view too long lines are not encouraged.

  • 2
    Thanks, I switched the ruleset.xml to 120 chars allowed per line so I don't get the pesky errors in my IDE :)
    – Vlad Preda
    Feb 11, 2013 at 13:24
  • 1
    Here are the rules from Magento 2: raw.github.com/magento/magento2/master/dev/tests/static/…. Word is that it's very likely they use them on Magento 1.x.
    – Bob Brodie
    Aug 26, 2013 at 16:40
  • 1
    Tim, do you think we should use the Magento code sniff? magento.stackexchange.com/a/8743/41 Oct 1, 2013 at 15:24
  • 1
    @BobBrodie - I'm managing Magento 1.x and I'm not aware of such changes coming to Magento 1.x. This would be a large and unnecessary change, leading to huge diffs for no reason. Magento 1 coding standard is ZF+, Magento 2 is PSR-1/2. Please see Zyava's answer for "official" sniffer. Dec 3, 2013 at 21:34

Here are latest Magento marketplace coding standard for Magento1 and Magento2

MEQP2 For Magento2

MEQP1 For Magento1


  • 1
    Made this as the accepted answer since these are the official coding standards. Thanks @QaisarSatti
    – Vlad Preda
    Dec 7, 2016 at 9:38

I'd like to submit that we should be using the Magento 2 code sniff as a standard for both Magento 1.X and 2.X: https://github.com/cobhimself/phpcs-magento-rules/blob/master/ruleset.xml

And here's essentially a mirror of that ruleset as a standalone repository: https://github.com/cobhimself/phpcs-magento-rules

  • 1
    I personally use: github.com/magento-ecg/coding-standard
    – B00MER
    Nov 13, 2013 at 18:51
  • 2
    Ah good call. I think the link I posted was referenced in a Magento 2 github discussion...any idea if/how the one you posted differs? It's certainly a more authoritative github account. Nov 14, 2013 at 3:34

This post is a bit old (2008) but I guess that it's still valid:

Is Magento following the ZF coding standards? Yes

With few exceptions, such as:

  • short open tags are allowed in templates.
  • concatenation dots are not enclosed in spaces.
  • indentation for for long lines hard wraps should be always one soft tab forward.

Edit As Tim worte in comment there are no short open tags in Magento core templatesa and it's best not to use them anyway as they are not recommanded (see here).

But my advice to you... Since you are writing your own module use your own coding style. From my experience you will make less mistakes when writing code in your own style, that you are familiar with, than if you follow Magento coding style one day and e.g. Wordpress coding style the next just because you are writing a module for a different website project.

  • 2
    I strictly don't agree. Community extension have to be readable for others.
    – user487772
    Feb 11, 2013 at 12:40
  • 2
    And I never saw short open tags in Magento.
    – user487772
    Feb 11, 2013 at 12:43
  • 1
    Point of oppinion. Since I've had quite a few years of experience with programming on different projects in different programming languages at the same time I've never had problems reading well structured code no matter the coding style but when it comes to rappidly switching between the projects and writting code it is far more benifitial to have the same style across your own code than it is to keep coding style compatibility with others outside your team. Feb 11, 2013 at 12:49
  • @DomenVrankar isn't assuming your code style is well structured and readable also an opinion? Whereas the teams behind the likes of Zend have many people making the decision as to what the style is and is known worldwide. Just food for thought...
    – Tom Burman
    Sep 28, 2015 at 13:44
  • I disagree too.
    – sv3n
    Feb 3, 2018 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.