Preview

Php Conventions and Coding Style

Powerful Essays
Open Document
Open Document
1229 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Php Conventions and Coding Style
PHP Conventions and Coding Style
● ● File and Directory Names Brackets ○ Curly Brackets ○ Class Brackets ○ Empty Brackets ○ Array Brackets ■ Opening Parenthesis ■ Closing parenthesis ● Single Dimension ● Multidimensional ■ Arrays as Function Arguments Naming Conventions ○ Classes ○ Functions and Methods ○ Variables Indentation String Concatenation Single Line Statements Comparison Operations Switch Structures Parentheses Ternaries Type Casting Constants Comments ○ One-line Comments Regular Expressions



● ● ● ● ● ● ● ● ● ● ●

Reference: http://kohanaframework.org/3.2/guide/kohana/conventions Syntax Highlighter: https://snipt.net

File and Directory Names
1. CamelCased should not be used. 2. Should be lowercase. Example: Incorrect ThisIsDirectory/ThisIsDirectory/ThisIsFile.php Correct this_is_directory/this_is_directory/this_is_file.php

Coding Standards
In order to produce highly consistent source code, we ask that everyone follow the coding standards as closely as possible.

Brackets
Please use BSD/Allman Style bracketing. Example: while (x == y) { something(); somethingelse(); }

The following is still syntactically correct:
//while (x == y) { something(); somethingelse(); }

As is this:
//for (int i=0; i < x; i++) //while (x == y) if (x == y) { something(); somethingelse(); }

Curly Brackets
Curly brackets are placed on their own line, indented to the same level as the control statement.
// Correct if ($a === $b) { ... } else { ... } // Incorrect if ($a === $b) { ... } else { ... }

Class Brackets
The only exception to the curly bracket rule is, the opening bracket of a class goes on the same line.
// Correct class Foo { // Incorrect class Foo {

Empty Brackets
Don't put any characters inside empty brackets.
// Correct class Foo {} // Incorrect class Foo { }

Array Brackets
Arrays may be signle line or multi-line array('a' => 'b', 'c' => 'd') array( 'a' => 'b',

'c' => 'd', )

Opening Parenthesis The opening array

You May Also Find These Documents Helpful

  • Good Essays

    Application code and comments should be written descriptively. The names of classes, methods and variables should be self-descriptive. Methods and classes will be commented to detail their…

    • 612 Words
    • 3 Pages
    Good Essays
  • Better Essays

    : "); ch = getche(); }while(ch == 'y' || stfor == NULL); } void…

    • 401 Words
    • 2 Pages
    Better Essays
  • Powerful Essays

    EAS230Syllabus

    • 1748 Words
    • 8 Pages

    C++ programming: editing, compiling, user I/O, variables (ints, doubles, char, strings, booleans), loops, decisions, functions, pointers, arrays, tables, databases, sorting.…

    • 1748 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    The expression 1 To 5 in the Case 1 To 5 clause specifies the range of numbers from ____.…

    • 595 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Macro Examples

    • 1120 Words
    • 5 Pages

    7. The If…Then…Else…End If code allows code to be conditionally executed depending on whether a specified logical condition has been met.…

    • 1120 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    The individual operations used in a computer program are often grouped into logical units called _____________.…

    • 4265 Words
    • 23 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Code for an Infinite Loop

    • 457 Words
    • 4 Pages

    An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.…

    • 457 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    java answers

    • 15737 Words
    • 160 Pages

    Building Java Programs 2nd edition Exercise Solutions Chapter 1 Chapter 2 Chapter 3a Chapter 3 G Supplement Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 15 Chapter 16 Chapter 17 Chapter 1 Exercise 1.1: Stewie public class Stewie { public static void main(String[] args) { System.out.println("//////////////////////"); System.out.println("|| Victory is mine! ||"); System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); } } Exercise 1.2: Spikey public class Spikey { public static void main(String[] args) { System.out.println(" \\/"); System.out.println(" \\\\//"); System.out.println("\\\\\\///"); System.out.println("///\\\\\\"); System.out.println(" //\\\\"); System.out.println(" /\\"); } } Exercise 1.3: WellFormed public class WellFormed { public static void main(String[] args) { System.out.println("A well-formed Java program has"); System.out.println("a main method with { and }"); System.out.println("braces."); System.out.println(); System.out.println("A System.out.println statement"); System.out.println("has ( and ) and usually a");…

    • 15737 Words
    • 160 Pages
    Powerful Essays
  • Good Essays

    long as you remain consistent (see p. 391). *Please adhere to professor guidelines at all…

    • 620 Words
    • 3 Pages
    Good Essays
  • Better Essays

    Arduino Handbook

    • 1883 Words
    • 8 Pages

    The basic structure of the Arduino programming language is fairly simple and runs in at least two parts. These two required parts, or functions, enclose blocks of statements.…

    • 1883 Words
    • 8 Pages
    Better Essays
  • Satisfactory Essays

    Hashing

    • 313 Words
    • 2 Pages

    Examples are used to explain key concepts. Each line of the programming code in these…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    C SHARP FUNDAMENTALS

    • 4128 Words
    • 20 Pages

    A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behaviour of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection. If the class is declared as static, then only one copy exists in memory and client code can only access it through the class itself, not an instance variable. For more information, see Static Classes and Static Class Members (C# Programming Guide).…

    • 4128 Words
    • 20 Pages
    Good Essays
  • Powerful Essays

    Chapter 1: An introduction to the marks of punctuation: period (.), question mark (?), exclamation mark (!), semi-colon (;), colon (:), parentheses (), dash (−), quotation marks (‘ ‘) and hyphen…

    • 14091 Words
    • 57 Pages
    Powerful Essays
  • Satisfactory Essays

    Economics Test Questions

    • 569 Words
    • 3 Pages

    The intended marks for questions or parts of questions are given in brackets [ ].…

    • 569 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    SANS 10143

    • 11638 Words
    • 101 Pages

    This standard will be revised when necessary in order to keep abreast of progress. Comment will be…

    • 11638 Words
    • 101 Pages
    Powerful Essays