Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

StarTutorial:
Modern PHP Developer - PSR
Oct 02, 2018 @ 18:21:50

If you're new to PHP or are working to enhance your skills, chances are you've at least heard of the PHP-FIG and the several PSRs that it has released to help provide structure around common functionality. In this article from StarTutorial they walk you through some of the basics of the more widely adopted PSRs including PSR-0/PSR-4 and PSR-3/PSR-4.

Prior to PHP Standards Recommendation (PSR), there were no truly uniformed standards for writing PHP code. For instance, for coding style, some people preferred Zend Framework Coding Standard, and some liked PEAR Coding Standards, and still others chose to create their own naming conventions and coding style.

[...] At the time of this writing, there are six accepted PSRs: two of them are about autoloading, two of them are related to PHP coding style and the remaining are about interfaces. In this chapter, we will discuss each PSR briefly. The purpose of this chapter is to introduce you to the ideas of PSRs. For further details on each one, the respective link are provided.

The post then goes through each of the major PSRs, describing them and providing code examples where relevant:

  • PSR-0 & PSR-4 for autoloading
  • PSR-1 & PSR-2 for coding standards
  • PSR-3 for logging interfaces
  • PSR-7 for HTTP message stricture

The post finishes with links to each of the PSRs on the PHP-GIF site for more information.

tagged: psr example psr0 psr4 psr3 psr2 psr1 psr7 tutorial phpfig

Link: https://www.startutorial.com/articles/view/modern-php-developer-psr

Fabien Potencier:
PHP CS Fixer finally reaches version 1.0
Nov 13, 2014 @ 15:34:34

Fabien Potencier has a new post to his site talking about a milestone for the PHP-CS Fixer tool (used to fix code to be compliant to the PSR-1 & PSR-2 standards) - a full, stable 1.0 release.

A few years ago, I wrote a small script to automatically fix some common coding standard mistakes people made in Symfony pull requests. It was after I got bored about all the comments people made on pull requests to ask contributors to fix their coding standards. [...] After a while, I decided to Open-Source the tool, like I do with almost all the code I write. [...] To my surprise, people started to use it on their own code, found bugs, found edge cases, added more fixers, and soon enough, we all realise that using regular expressions for such things is doomed to fail.

In recent months the tool has undergone a rewrite to work with the tokens instead of regular expressions (lead by Dariusz Ruminski) and the 1.0 release of this updated version has been made:

After 13,000 additions and 5,000 deletions, I'm very proud to announce version 1.0 of PHP-CS-Fixer; it is smarter, it is more robust, and it has more fixers. Any downsides? Yes, speed; the tool is much slower, but it is worth it and enabling the new cache layer helps a lot.
tagged: phpcs fixer tool release stable v1 fabienpotencier dariuszruminski psr2 psr1

Link: http://fabien.potencier.org/article/76/php-cs-fixer-finally-reaches-version-1-0

NetTuts.com:
PSR-Duh!
Apr 12, 2013 @ 15:46:26

On NetTuts.com today there's a post that talks about applying the PSR formatting to your application's code. If you haven't already read their introduction to the PSRs, it's highly suggested.

In a previous lesson here on Nettuts+, you learn about PSR; however, that article didn’t detail the process of integrating that coding style into your projects. Let’s fix that!

They briefly recap the main two PSRs (PSR-1 and PSR-2, but no mention of PSR-3 the logging interface) and show code examples of them being applied. They also point to the PHP_CodeSniffer tool that you can use to keep your code in the correct structure. Instructions are included to install it specifically for the Sublime Text 2 editor via package control. It's just a command-line tool, though, so it could be integrated with just about any other editor/IDE out there too.

tagged: psr psr1 psr2 apply autoload formatting phpcodesniffer

Link: http://net.tutsplus.com/tutorials/tools-and-tips/psr-duh

Chris Hartjes:
Standards, Soapboxes, and Shamans
Jan 21, 2013 @ 19:16:47

In this latest post to his site Chris Hartjes shares some of his thoughts about the recently approved PSR-3 standard (for logging) and some of the reception that the other PSRs (PSR-0, 1 & 2) have gotten from the PHP community.

For those who pay attention to the workings of the PHP community you might have heard about the “PHP Standards Recommendations” that have been coming out of the PHP Framwork Interop Group. [...] More recently this group has been working on a standard for logging interfaces called PSR-3. I spoke about this on Twitter, and I will repeat it here: I think PHP programmers should get behind PSR-0 and efforts like PSR-3. I feel that PSR-1 and PSR-2 are solutions looking for a problem and seem, to me anyway, to me out of place with the solutions offered by PSR-0 and PSR-3.

He likens the PHP PSRs to the Python enhancement proposals (PEPs) and, more specifically, to the PEP-8 - their own version of "coding standards" that was highly championed by Guido van Rossum and put into wide practice.

Any programming language community that does not work as hard as possible to make it easier to integrate other’s libraries of code together [by standardizing their formatting] is asking for irrelevancy.
tagged: standards psr0 psr1 psr2 psr3 community feedback python pep

Link:

Project:
PHPHint.org - Online PHP Code Analysis
Aug 08, 2012 @ 15:18:59

Klaus Silveira has submitted a project he's come up with to help PHP developers detect problems in their code via a web-based application - PHPHint.org.

PHPHint is a community-driven, quick and easy to use, online tool that analyzes your PHP code and looks for potential errors, lack of best practices and code smell. It also allows you to clean your code automagically.

It was created to spread the work about the PSR standards and the PHP-FIG group, the importance of getting rid of code smell and applying to standards.

Since it is an open source project, you can help contribute if you'd like to see improvements to the service. It's great that it takes the relatively new PSR standards (PSR-1 & PSR-2) into account when analyzing the code too.

tagged: phphintorg code analysis online psr1 psr2

Link:

Phil Sturgeon's Blog:
PHP: Ecosystem Update
Jul 11, 2012 @ 14:25:28

In this new post Phil Sturgeon looks at two movements in the PHP community that are doing positive things for the language and the community as a whole - the Framework Interoperability Group (PHP-FIG) and the more recent "PHP The Right Way" initiative.

Don't worry guys, this isn't another PHP apologist or PHP hater blog. We've all had enough of those recently. This is a quick heads up on two projects that are doing what they can to make the PHP ecosystem a better place.

He talks a bit about some of the recent work that the PHP-FIG has done, the new standards that were approved by the group (PSR-1 & PSR-2) as well as the launch of a dedicated website for the project, complete with a handy FAQ. He also points out the PHP The Right Way site and the loads of community contributions that have come in around it. There's guidelines for things like dependency management, security, testing, deployment and lots more. If you haven't gotten a chance to check out this resource, it's definitely work a look!

tagged: ecosystem update language rightway phpfig psr1 psr2 community

Link:

Project:
CodeSniffer for PSR's (PSR-0, PSR-1 & PSR-2)
Jun 09, 2012 @ 16:17:50

Klaus Silveira has created a set of PHP_CodeSniffer rules that can be used to test your code for the recently approved PSR-1 & PSR-2 standards.

This is a PHP_CodeSniffer sniff to check against the PHP Standard Resolutions: PSR-0, PSR-1 and PSR-2. Those standards were approved by the PHP Framework Interoperability Group. You can read more about the PHP FIG and the PSR's on this excellent article by Paul Jones.

The github repository also provides an overview of the standards themselves and how to get these sniffs installed.

tagged: psr codesniffer rules psr0 psr1 psr2

Link:

Community News:
Kohana Community Responds to PSR-1 & PSR-2
Jun 09, 2012 @ 14:10:59

In the Kohana framework, you can get an inside look at the discussion inside a framework community regarding their adherence to the PSR-1 & PSR-2 standards (hint: they're not in favor).

A commentor asks the question "Will Kohana eventually follow the following guidelines?" and is immediately given the simple response of "no". Other comments reinforce this by pointing out some of the differences in the standards that the framwork follows and what the PSR standards outline.

Other posters make comments about the PHP-FIG group themselves, some of the things outlined in the standards and some of their own personal preferences when it comes to the the standards of their own code. You can find more information on the standards here: PSR-1 and PSR-2.

tagged: kohana framework community opinion standards phpfig psr1 psr2

Link:

Paul Jones' Blog:
PHP-FIG: PSR 1 and 2 Accepted
Jun 05, 2012 @ 14:27:15

As Paul Jones mentions in his latest post to his site, the much talked-about PSR standards that were proposed by the PHP-FIG group, PSR-1 and PSR-2, have been accepted.

Earlier today, the PHP Framework Interoperability Group accepted two standards recommendations. [...] There's been a lot of commentary about these proposals over the past two weeks, some of it positive and some of it negative.

He includes links to some of the commentary that's been made about the standards recently, and spends some time responding to some of the negative comments specifically, like:

  • What the hell is the "PHP Standards" group? I've never heard of it before now.
  • Why are you guys so secretive and closed?
  • So once I join the list, I can vote on PHP-FIG Standards Recommendations? Sweet!
  • Whatever. I don't need you guys telling me what to do. If I don't want to follow your so-called "standards" then you can't make me.
tagged: psr1 psr2 standard interoperability framework phpfig approval

Link:

PHPMaster.com:
PSR-1 and PSR-2 to be Approved as Standards
May 22, 2012 @ 18:18:40

As is mentioned in this new post to PHPMaster.com, the PHP standards group is officially in the voting process on two new standards (PSR-0 being the first) setting up some standard development practices for PHP applications - PSR-1 and PSR-2.

They initially started out as one proposal but the initial round of voting didn’t yield a majority in favor. Participants did however see merit in various requirements the decision was made to split it into 2 proposals - one for mandatory interoperability and one for suggested style.

The PSR-1 standard proposes some basic coding standards (like namespacing structure and class/method naming definitions) and the PSR-2 standard covers similar things, but more in-depth with more recommendations.

If you want to find out how your application stacks up against this new standard, you can try out PHP-CS-Fixer (from Fabien Potencier) to see how many things need an update.

tagged: psr0 psr1 psr2 standard coding convention voting

Link:


Trending Topics: