Learn Code Igniter Coding Standards

Code Igniter Coding Standards

Coding Standards put a crucial part in any programming language for achieving a high code quality and to write more lucid and clean code.

Here is the list of some best coding standards.

  • Upgrade to the Latest Version of PHP
  • Use only regular PHP Opening and closing tags, don’t utilize short tags and other php opening and closing tags.

Ex:

Bad

<?

// php code Block – php short tags

?>

Good

<?php

// php code Block

?>

  • Indent code appropriately.
  • The closing?> tag MUST be excluded from files containing only PHP.
  • PHP keywords must be in lowercase, The PHP constants true, false, and null MUST be in lower case
  • Always comment your code
  • Avoid unnecessary Variables (not duplicate variables pointlessly)

Ex:

Bad

<?php

$name = trim($_POST[‘name’]);

echo $name;

Good

<?php

echo trim($_POST[‘name’]);

Naming Conventions:

Variable Naming Conventions:

  • Case should never be used to distinguish between variable names. Every variable title within the current scope should be completely unique. Variable names should depict the content that they (will) contain, using either complete words or understandable abbreviations.
  • Use “lowerCamelCase” style (lowercase lettering on beginning and capitalization on subsequent words) to name variable.
  • Global variables should be prepended with a ‘g’.
  • Global constants should be all caps with ‘_’ separators

Class Name Naming Conventions:

  • Class Name Should Begin with Capitalized Letter
  • Class name should only contain alphanumeric characters. Numbers are allowed in class names but are debilitated in most cases. Underscores and Capitalized letters are allowed in place of the word separator(first letter of each word)

Constant Naming Conventions:

  • Constant Name should be Capitalized and we can separate each word with underscore.

Method and functions Naming Conventions:

  • Method names MUST be beginning with lowercase.
  • Use underscore or CaseChange methods to separate words

Comments

  • C fashion comments (/* */) and standard C++ comments (//) are both fine. Utilize of Perl/shell style comments (#) is disheartened.Database
  • Reduce the Number of Database Queries

There can be numerous more points which should be considered while writing your PHP program. Over all intention should be to be consistent throughout of the code and it’ll be possible only when you will follow any coding standard.



Leave a Reply

We use cookies to ensure that we can give you the best experience on our website. If you Want to use this website you are allowing to the use of these cookies. Check our privacy policy for more details.
Contact Us Today!

We are glad that you preferred to contact us. Please fill our short form and one of our friendly team members will contact you back.

X
Quick Quote