"PHP is the best programming language";-) So what code specification does Phper get used to? sideeffect.kr some interesting results by analyzing the open source code hosted on GitHub, let's take a look.
Indent in
Space (70.172%), Tab (29.828)
Based on 600,614-time commit statistics.
Position of curly braces when defining a class
Exclusive Row (55.703)
class Foo{ // ...}
Not exclusive one row (44.297%)
class Foo { // ...}
Based on 68,516-time commit statistics.
Control the position of the statement curly braces
Same line (65.937)
if($baz) { // ..} elseif($bar) { // ..} else { // ..}while ($i <= 10) { // ..}switch($beer) { // ..}
Not travelling (34.063)
if($baz){ // ..}elseif($bar){ // ..}else{ // ..}while ($i <= 10){ // ..}switch($beer){ // ..}
Based on 292,588-time commit statistics.
Method defines the position of the curly brace
Same line (64.442)
function bar($baz) { // ...}
Not travelling (35.558)
function bar($baz){ // ...}
Based on 65,030-time commit statistics.
Space around conditional statements
With spaces (89.979)
if ($baz) { // ...} elseif ($bar) { // ...} else { // ...}while ($i <= 10) { // ...}switch ($beer) { // ...}
No spaces (10.021)
if($baz){ // ...}elseif($bar){ // ...}else{ // ...}while($i <= 10){ // ...}switch($beer){ // ...}
Based on 219,583-time commit statistics.
Conditional statement Inner Space
No spaces (82.808)
if ($baz) { // ...} elseif ($bar) { // ...}while ($i <= 10) { // ...}switch ($beer) { // ...}
With spaces (17.192)
if ( $baz ) { // ...} elseif ( $bar ) { // ...}while ( $i <= 10 ) { // ...}switch ( $beer ) { // ...}
Based on 296,011-time commit statistics.
Method declaration Parameter external
No spaces (82.407)
function bar($baz){ // ...}
With spaces (17.593)
function bar ($baz) { // ...}
Based on 15,519-time commit statistics
Method declaration Parameter interior
No spaces (84.828)
function bar($baz){ // ...}
With spaces (15.172)
function bar( $baz ){ // ...}
Based on 52,324-time commit statistics
Class name
Pascalcase (75.973%)
class FooBarBaz { // ...}
Snake_pascal_case (14.564%)
class Foo_Bar_Baz { // ...}
Snake_case (6.025%)
class foo_bar_baz { // ...}
CamelCase (2.851%)
class fooBarBaz { // ...}
Snake_first_letter_uppercase (0.299%)
class Foo_bar_baz { // ...}
Caps_snake_case (0.287%)
class FOO_BAR_BAZ { // ...}
Based on 60,467-time commit statistics.
Constant
Caps_snake_case (97.511%)
const BAR_BAZ = 0;define(‘BAR_BAZ‘, 0);
Snake_case (1.088%)
const bar_baz = 0;define(‘bar_baz‘, 0);
CamelCase (0.842%)
const barBaz = 0;define(‘barBaz‘, 0);
Pascalcase (0.507%)
const BarBaz = 0;define(‘BarBaz‘, 0);
Snake_pascal_case (0.052%)
const Bar_Baz = 0;define(‘Bar_Baz‘, 0);
Based on 30,144-time commit statistics.
Name of function
CamelCase (74.26%)
function barBaz(){ // ...}
Snake_case (23.644%)
function bar_baz(){ // ...}
Pascalcase (1.868%)
function BarBaz(){ // ...}
Caps_snake_case (0.14%)
function BAR_BAZ(){ // ...}
Snake_pascal_case (0.087%)
function Bar_Baz(){ // ...}
Based on 185,946-time commit statistics
Method declaration
Static after visibility (85.272)
class Foo{ public static function bar($baz) { // ... }}
Abstract (or final) before visibility (7.483)
class Foo{ abstract public function bar($baz); // ...}
Static before visibility (5.519)
class Foo{ static public function bar($baz) { // ... }}
Abstract (or final) after visibility (1.726)
class Foo{ public abstract function bar($baz); // ...}
Based on 45,467-time commit statistics.
The statistical classification is inappropriate here. Should be split into two categories of statistics respectively.
Maximum line width
80 characters (90.269)
120 characters (7.074)
150 characters (2.657)
Based on 636,577-time commit statistics
Compiling Segmentfault
Original: 1190000000443795
The most popular PHP code specification