32
loading...
This website collects cookies to deliver better user experience
Just the Gist
PHP Standard Recommendation 1 (PSR-1) is Basic Coding Standards for PHP. It is a set of coding standards that gives us a recommended way to structure our code.
<?php
or <?=
in our files. This means that we should avoid using <?
. The tag <?
should be avoided since it can cause issues when generating XML documents. If you want to use it though, the setting short_open_tag
in php.ini
controls this.
HomeController
with a namespace App\Controller
should be placed in folders and a file such as App\Controller\HomeController.php
. Having multiple classes in a file is not recommended.<?php
// Path: .\src\App\Controller\HelloController.php
namespace App\Controller;
class HelloController
{
const HELLO_WORLD = 'Hello World';
public function helloWorld()
{
echo self::HELLO_WORLD;
}
}
$PascalCase
, $camelCase
or $snake_case
. declare
statements when present, to omit ?>
when dealing with files containing only PHP code, and how to use the use
statements. If you feel the need to find more structure for your projects, PSR-1 and PSR-12 are good places to start!