Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Last active December 21, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philsturgeon/6378999 to your computer and use it in GitHub Desktop.
Save philsturgeon/6378999 to your computer and use it in GitHub Desktop.
PSR-2 Control Structures and Statements

Class/method blocks:

These things are "blocks" of code, always on their own lines because they are always by themselves.

<?php
class Foo
{
  public function doSomeShit() 
  {
  
  }

}

Control Statements

These flow into each other because they are connected.

<?php
if (true) {
  // stuff
} else {
  // bla
}

try {
  // do stuff
} catch (Foo $e) {
  // AAAHH
}

Allman says:

<?php
if (true)
{
  // stuff
}

// Some big long comment about something
// and it spans over a few lines 
// and it might end up off the bottom of the screen
// so you could not spot the else
else
{
  // bla
}

That was never planned, it was a random result of a poll which decided things were going to work that way, but im pretty happy about the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment