Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Do you follow the PSR Standards

I've been doing PHP just over 3 weeks now and recently moved onto learning OOP and Design Patterns like MVC because when I do something I like doing it right, so I googled and found phptherightway.com
which lead me to php-fig.org so I decided to follow them and have already started to implement the best practices in projects.

So I was wondering if anyone else follows the PSR standards, and if so do you have any tips?

What I use:

Sublime Text 3
iTerm2
Vagrant LAMP Stack
I don't mind it but that's because I am new, but if you've been coding a while you tend to pick up your own style and can be hard to change, but what I can't argue with is having an space for things like foreach and if, which adds to the readability.

PHP Code

<?php 
$names 
= ['Nicholas Cage', 'Adam Sandler', 'Liam Neeson'];

/* PSR-2 Compliant */
foreach ($names as $name) {
    
// loop
}

/* Not PSR-2 Compliant */
foreach($names as $name) {
    
// loop
} 

But if you're stuck in writing your code without complying to PSR-2 but want to, you can simply run PHP_CodeSniffer which will check your code, and in some cases fix most of your mistakes automatically and tell you the lines of the others which it can't. I use the command line version but there are plugins available.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[The Brotherhood] by VinavilMar 27, 2026 09:05 AM 25 860 Mar 27, 2026 09:05 AM
Last Post: Vinavil
[PHP] by SIM-1947090Aug 13, 2016 11:41 AM 0 207 Aug 13, 2016 11:41 AM
Last Post: SIM-1947090
[PHP] by IdolizeSep 26, 2015 04:59 AM 3 156 Sep 26, 2015 04:59 AM
Last Post: c00perzz