PHP File FormattingTagsPHP code must always being with the long form opening tag. If a file contains only PHP code, the end tag may optionally be omitted from the end of the file. IndentationTabs should always be used for indentation. Spaces should never be used for indentation. We live in a world where IDEs can be configured to display tabs at variable lengths, so configure your tab width to what you feel comfortable with. Line LengthLines should be designed such that a reader can avoid horizontal scrolling, except in cases where scrolling offers improved readability over word-wrapping. As the resolution and width of monitors has increased the standard with of 80 characters (previously the width of a punch card) no longer holds any relevance. Use your best judgement to determine where lines should wrap. EOLEvery line should terminate with a line-feed (LF) character only. That is '\n', also known as hex value 0x0A. Do not use CRLF (Window systems) or CR (Mac systems). Character EncodingAll PHP files should be encoded using UTF-8, with no byte-order-mark (BOM). Programming StylesStringsLiteralsStrings consisting of more than one character should be surrounded with double-quotes ("). Strings consisting of only a single character may be surrounded with single-quotes ('). $str = "This is a long string";
$chr = 'a'; |
ConcatenationRun-on StringsA string whose length requires it to wrap multiple lines should be concatenated with the concatenation character (.) appended at the end of the line, with the carry-over line indented below it. $str = "This is a string that needs to " .
"wrap onto another line."; |
Variable SubstitutionWhen a variable needs to be added to a string the string should be broken open and concatenated together to improve readability. $name = "Hefo Quient Esbit";
$str = "Hello " . $name . "! How are you?" |
ArraysNumerically Index ArraysAssociative ArraysMultidimensional ArraysConditionalsLoopsMethodsCommentsDoc CommentsInline Comments |