- Filenames are case sensitive
- Allowed charset: a-zA-Z0-9-.
- Spaces are not allowed
Follow PSR-1 and PSR-2 Coding Standards.
- Extensions: .php
- Filename: PascalCase.php
- One class per file
- Singular
- ClassName + "Controller"
- ModelName
- "Abstract" + AbstractName
- InterfaceName + "Interface"
- camleCase
- Underscore is not allowed
- lowercase_under_score
- Class methods must defined as public or protected
public function getValue()
{
// ...
}
- camelCase
- No data type prefix
- Arrays with a collection of data should be named plural
<?php
$userName = 'admin';
$count = 100;
$amount = 123.45;
$i = 0;
$status = true;
$rows = array();
$customer = new Customer();
$db = $this->getDb();
<?php
$result // Mixed return value
// Parts of file name and path
$file // Full filename with directory, filename and extension (/tmp/file.txt)
$fileName // Filename with extension (file.txt)
$extension // Filename extension without dot (txt)
$baseName // Filename without extension (file)
$path // Full path to directory name without filename (/tmp)
$directory // Name of a single folder (e.g. tmp)
// Arrays
$params // Array with function paramameters e.g. function demo($params) { ... }
$rows // Array of rows (from select query)
$row // A single row
$value = 'variant datatype';
- lowercase, underscore
- singular if data type is string, int, float or oject
- plural if data type is array
$rows = array();
$rows[0] = array();
$rows[0]['username'] = 'max';
$rows[0]['status'] = true;
or
$rows = array();
$rows[0] = array(
'username' => '...',
'status' => true
);
- Use PHPDoc
- Google HTML&JS Style Guide: https://google.github.io/styleguide/htmlcssguide.html
- Extensions: .html.php or .twig
- Name: lower-kebab-case.html.php, my-fancy-page.twig
- Extension: .js
- Use jQuery style: lower-kebab-case.js
- Examples: bootstrap.js, jquery.min.js, jquery-3.2.1.min.js, foo-library.bar.js
- Use JSDoc
- JSDoc Wiki
- camelCase
- No data type prefix
- Arrays index names should be plural
var userName = 'admin';
var total = 100;
var amount = 29.99;
var visible = true;
var config = {}
var rows = [];
var value = 'something';
- Lowercase for object and array element names
- no prefix
// good
var row = {};
row.id = 100;
row.username = 'admin';
// good
var row = {
id: 100,
username: 'admin'
};
// bad
var row = [];
row.Id = 100;
row.UserName = 'admin';
- Extension: .css
- Format: lower-kebab-case.css
- Examples: bootstrap-theme.css, jquery-ui.min.css
- Class name: lower-kebab-case
.my-super-class-name {}
- ID name: lower-kebab-case
#email
#field-with-long-id
#my-modal
#anchor-name