Standard Code Rule(PHP)

Here following standard rule use while code .

1. Do not put duplicate html code when conditions
example
if ( $page == ‘index.php’ ):
<li><a href=”index.php” class=”menu selected”>Home</a></li>
else:
<li><a href=”index.php” class=”menu”>Home</a></li>
endif;

2. Ever try to use ternary operator when single line or assignment conditionally
example
$variable = $user == ‘administrator’ ? ‘Welcome Admin’ : ‘Welcome ‘.$user;
echo ( $act == ‘add’ ) ? ‘New Record’ : ‘Modify Record’;

3. Write code and review your code 2 times before apply
Put yourself being computer to execute the code will help to improve your code

4. Option to Review code is ask your colleague to check your code same way as above

5. Put one line description that what is the code is doing / performing

6. Never use $_POST, $_GET, $_REQUEST directly.
example
$myvar = ”;
if ( !isset($_REQUEST[‘myvar’]) ) $myvar = $_REQUEST[‘myvar’];

7. Unset all objects you used in PHP file at the end of the script. unset($obj)

8. No need to put, !empty($object) where you are using foreach($object as $k => $v)

9. Indentation require to understand the logic you wrote by other developer or yourself

10. What is the difference between require and require_once?

11. try to use single quote with echo if not used any varible within string
example
echo ‘hello ‘.$ajay;
echo “hello $ajay”;

12. form inputs
always do prictice to selfclose for input type like hidden, text, button, submit, image etc..

13. try to use css based animation / menu instead of javascript because css3 is good to do the same

14. use: instead of { for if, foreach, while and switch when it’s within view template

15. Non Credential redirection logic should always at the top not anywhere else

16. Do not use any standard keyword for variable

Useful Website for PHP Developer(Author: Bharat Rawal PHP developer)

Here  below many links addedd for help each and every PHP developer want to learn and apply new things.

 

  1. http://www.freeformatter.com/html-formatter.html
  2. http://www.tuxradar.com/practicalphp
  3. http://www.smashingmagazine.com/2009/06/28/50-free-resources-that-will-improve-your-writing-skills/
  4. http://www.phpeveryday.com/articles/PHP-Data-Object/PDO-Tutorial-P842.html
  5. http://www.revillweb.com/articles/web-developers-what-should-you-be-learning-in-2014/
  6. http://www.revillweb.com/articles/web-developers-what-should-you-be-learning-in-2014/
  7. http://www.lynda.com/CakePHP-tutorials/CodeIgniter-flow-architecture/92562/99660-4.html
  8. http://www.php4every1.com/
  9. http://www.sanfoundry.com/1000-php-questions-answers/
  10. http://phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html
  11. http://www.a2zwebhelp.com/pay-through-paypal
  12. http://www.scriptcase.net/scriptcase-features/
  13. https://www.dreamhost.com/dreamscape/2013/08/27/mysql-indexing-basics/
  14. http://www.phpgang.com/how-to-create-restful-api-webservice-with-slim-php-and-mysql_588.html
  15. http://hackmysql.com/case4
  16. http://www.sitepoint.com/using-explain-to-write-better-mysql-queries/
  17. http://code.tutsplus.com/tutorials/24-best-practices-for-ajax-implementations–net-9180
  18. http://www.sitepoint.com/14-free-tools-to-validate-your-html-css-rss-feeds/
  19. http://www.tutorialspoint.com/ajax/ajax_database.htm
  20. http://ellislab.com/codeigniter/user-guide/doc_style/index.html
  21. http://perishablepress.com/stupid-htaccess-tricks/

Enjoy With PHP programing …….

Checkout from GITHUB

Every project has an associated Git associated link.

Let’s take the example of  softbharat demo. The project codebase is available at

http://github.com/softbharat/demo

 

The associated git link is

http://github.com/softbharat/demo.git

 

To download the code,

$ git clone http://github.com/softbharat/demo.git
Initialized empty Git repository in /home/user/experiments/git/demo/.git/
remote: Counting objects: 6865, done.
remote: Compressing objects: 100% (4446/4446), done.
remote: Total 6865 (delta 2272), reused 6435 (delta 2063)
Receiving objects: 100% (6865/6865), 2.46 MiB | 29 KiB/s, done.
Resolving deltas: 100% (2272/2272), done.

Now list the directory contents
ls 
softbharat

ls demo/
index.php
readme

Hurrah !! You successfully checkout on your domain. Enjoy :-)