Language and development rules: Difference between revisions

Jump to navigation Jump to search
m
No edit summary
Line 70: Line 70:
* Use "include_once" for anything with functions or class definitions in it (like *.class.php and *.lib.php files), use "include" for template-style php with files containing common part of HTML and PHP code (like *.inc.php and *.tpl.php files).
* Use "include_once" for anything with functions or class definitions in it (like *.class.php and *.lib.php files), use "include" for template-style php with files containing common part of HTML and PHP code (like *.inc.php and *.tpl.php files).


* Coding style to use is the PSR-2 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) with 2 exceptions, this means:
* Coding style to use is the PSR-2 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). There is however exceptions:
** Files must be saved with Unix format (LF) and not Windows (CR/LF). Unix format is compatible on all OS such as Unix like, Windows, Mac, but the Windows text file format may not work on some PHP under Unix.
** Length of line: We accept more than 80 characters per line. 80 is a max length introduced with fist computers when screen was text only and is nowday very low. In most cases, we don't go over 80 characters, but sometimes (when declaring a list of reference arrays, like in the module descriptor files), it is better to have long lines instead of long page with code content that is just data declaration and does not contain any logic.
** Smart tags PHP are not used. PHP code section must start with '''<?php'''
** But there is an exception of length of line: We accept more than 80 characters per line. 80 is really too low. In most cases, we never go over 80, but sometimes (when declaring a list of reference arrays, like in the module descriptor files), it is better to have long lines instead of long page with code content that is just data declaration and does not contain any logic.
** The other exception is that we don't replace the tab with space. This makes lot of editor crazy and breaks some auto-format features.
** The other exception is that we don't replace the tab with space. This makes lot of editor crazy and breaks some auto-format features.
You can use the file dev/codesniffer/ruleset.xml as rule file to control coding style with PHPCodeSniffer.
** The following rule is also added:
*** Files must be saved with Unix format (LF) and not Windows (CR/LF). Unix format is compatible on all OS such as Unix like, Windows, Mac, but the Windows text file format may not work on some PHP under Unix.
*** Smart tags PHP are not used. PHP code section must start with '''<?php'''
** You can use the file dev/codesniffer/ruleset.xml as rule file to control coding style with PHPCodeSniffer.
** You may note that current code is not yet compliant with this rule. The reason is that we must "now" follow the PSR-2, but it wasn't in the past. So feel free to change coding style to match new rules.


== Classes and properties structures ==
== Classes and properties structures ==

Navigation menu