PSR-1 - Basic Coding Standard - PHP-FIG
PSR-1 - Basic Coding Standard - PHP-FIG
1 de 6
http://www.php-fig.org/psr/psr-1/
PHP-FIG
Home
Recommendations (PSRs)
Members
Bylaws
FAQs
Get Involved
PSR-1: Basic Coding Standard
1. Overview
Files MUST use only <?php and <?= tags.
Files MUST use only UTF-8 without BOM for PHP code.
Files SHOULD either declare symbols (classes, functions, constants, etc.)
or cause side-effects (e.g. generate output, change .ini settings, etc.) but
SHOULD NOT do both.
Namespaces and classes MUST follow an "autoloading" PSR: [PSR-0,
PSR-4].
Class names MUST be declared in StudlyCaps .
Class constants MUST be declared in all upper case with underscore
separators.
Method names MUST be declared in camelCase .
2 de 6
http://www.php-fig.org/psr/psr-1/
2. Files
2.1. PHP Tags
PHP code MUST use the long <?php ?> tags or the short-echo <?= ?> tags; it
MUST NOT use the other tag variations.
<?php
3 de 6
http://www.php-fig.org/psr/psr-1/
// declaration
function foo()
{
// function body
}
<?php
// declaration
function foo()
{
// function body
}
// function body
}
}
4 de 6
http://www.php-fig.org/psr/psr-1/
<?php
class Foo
{
}
Code written for 5.2.x and before SHOULD use the pseudo-namespacing
convention of Vendor_ prefixes on class names.
<?php
4.1. Constants
5 de 6
http://www.php-fig.org/psr/psr-1/
<?php
namespace Vendor\Model;
class Foo
{
const VERSION = '1.0';
const DATE_APPROVED = '2012-06-01';
}
4.2. Properties
This guide intentionally avoids any recommendation regarding the use of
$StudlyCaps , $camelCase , or $under_score property names.
4.3. Methods
Method names MUST be declared in camelCase() .
Available translations:
English (official)
6 de 6
Follow us on Twitter
http://www.php-fig.org/psr/psr-1/