Wednesday, January 9, 2013

Must Know- Php Developers


1. Use PHP Core Functions and Classes
If you’re trying to do something that seems fairly common, chances are, there’s already a PHP function or class that you can take advantage of. Always check out thePHP manual before creating your own functions. There’s no need to create a function to remove the white space at the beginning and at the end of a string when you can just use the trim() function. Why build an XML parser for RSS feeds when you can take advantage of PHP’s XML Parser functions (such as xml_parse_into_struct)?
2. Create a Configuration File
Instead of having your database connection settings scattered everywhere, why not just create one master file that contains its settings, and then include it in your PHP scripts? If you need to change details later on, you can do it in one file instead of several files. This is also very useful when you need to use other constants and functions throughout multiple scripts.
Using a config file is a popular web application pattern that makes your code more modular and easier to maintain.
3. Always Sanitize Data That Will Go into Your Database
SQL injections are more common that you may think, and unless you want a big headache later on, sanitizing your database inputs is the only way to get rid of the problem. The first thing you should do is learn about popular ways your app can be compromised and get a good understanding of what SQL injections are; read about examples of SQL injection attacks and check out this SQL injection cheat sheet.
Luckily, there’s a PHP function that can help make a big heap of the problem go away:mysql_real_escape_string. mysql_real_escape_string will take a regular string (learn about data types through this PHP variables guide) and sanitize it for you. If you use the function together with htmlspecialchars, which converts reserved HTML characters (like <script> becomes &lt;script&gt;), not only will your database be protected, but you’ll also safeguard your app against cross-site scripting (XSS) attacks when rendering user-submitted HTML (such as those posted in comments or forum threads).
4. Leave Error Reporting Turned On in Development Stage
Looking at the PHP White Screen of Death is never helpful except for knowing something is definitely wrong. When building your application, leave error_reportingand display_errors turned on to see run-time errors that will help you quickly identify where errors are coming from.
You can set up these run-time configurations in your server’s php.ini file or, if you don’t have access to override the directives in this file, set them on top of your PHP scripts (using the ini_set() function to set display_errors to 1, but it has its limitations when done this way).
The reason behind turning on error reporting is quite simple — the sooner you know about your errors, the faster you can fix them. You might not care about the warning messages that PHP might give you, but even those usually signal towards a memory-related issue that you can take care of. When you’re done building out your application, turn error_reporting and display_errors off or set their values to a production-ready level.
5. Don’t Over-Comment Your Code
Proper documentation of your code through comments in your scripts is definitely a good practice, but is it really necessary to comment every single line? Probably not. Comment the complicated parts of your source code so that when you revisit it later you’ll quickly remember what’s going, but don’t comment simple things such as your MySQL connection code. Good code is self-explanatory most of the time.
Good Example of Commenting
<?php

  /* CONNECT TO THE DATABASE */

  $hostname = "localhost";
  $username = "";
  $password = "";
  $dbname = "";

  $connectionStatus = mysql_connect($hostname, $username, $password) or die(mysql_error());
  $selectionStatus = mysql_select_db($dbname) or die(mysql_error());

  /* END DATABASE CONNECTION */

?>
Bad Example of Commenting
<?php

  /* DEFINE THE CONNECTION VARIABLES */
  $hostname = "localhost"; // Hostname
  $username = ""; // Username
  $password = ""; // Password
  $dbname = ""; // Database name
  // Connect to the database or display an error
  $connectionStatus = mysql_connect($hostname, $username, $password) or die(mysql_error());
    // Select our database here    
    $selectionStatus = mysql_select_db($dbname) or die(mysql_error());

?>
6. Keep Favorite Code Snippets Handy
You’ll be coding a lot of the same things throughout your PHP development career, and keeping code snippets always available will help you save a lot of time. There are several apps that can keep and sync your code snippet collection for you, so no matter where you are, you can always have your snippets available. Some apps you can use to corral your code snippets are Snippet, snippely, Code Collector, and Snipplr(web-based).
Most integrated development environments (IDEs) such as Eclipse (which can store code templates) and Dreamweaver (via the Snippets Panel) may have built-in features for storing code snippets.
Even a simple and well-organized directory called snippets that contain text files (or PHP scripts) — and possibly synced in the cloud using an app like Dropbox if you use multiple computers — can do the trick.
7. Use a Good Source Editor to Save You Time
Your editor is where you’ll spend the majority of your time, so you want to use something that helps you save time. Syntax highlighting is a must and definitely something you should be looking for as a software feature. Other bonuses include code hinting, code navigation and built-in debugging tools. All of these features can end up saving you massive amounts of time. An example of a source code editor/IDE for PHP is phpDesigner.
Take the time to get familiar with your source code editor’s features by reading the documentation and reading tutorials online. A bit of time investment in this arena can really streamline your coding workflow.
Check out this list of source code editors for developers as well as this list of free text editors for coders to discover popular code-editing applications.
8. Use a MySQL Administration Tool (Like phpMyAdmin)
I know some crazy hard-core developers who like working with MySQL (the popularDatabase Management System pairing for PHP) via command line, which, to me, is inefficient and just, well, crazy. It’s a good thing to know how to administer your MySQL database using mysqladmin, but afterwards, you should use a graphical user interface like phpMyAdmin to speed up database development and administration.
Use a Good Source Editor to Save You Time
phpMyAdmin, in particular, is an excellent open source database viewer/manager that allows you to view your MySQL databases graphically so that you don’t have to waste time doing things via the command line. You can quickly build databases and their tables, export your databases into SQL files, run SQL queries, optimize tables, check for issues, create MySQL database users and set up their privileges quickly, and much more. There is a good chance your web host already has phpMyAdmin installed, and if not, it only takes minutes to install.
Check out this list of the best MySQL database management tools and this list ofMySQL apps for alternatives to phpMyAdmin.
9. Use a PHP Framework
It took me a really long time to accept the fact that using a web application development/rapid application development framework would help me out. You have a small learning curve in the beginning, and there will be a lot of reading to do to learn how the API of the framework works, but you get amazing productivity and efficiency benefits later. Using a framework forces you to use better web development patterns that you might not be using right now.
Using a PHP framework pays off big time when you have to share your code with others later on or when you have to work together with someone; it gives you a standardized platform for building web applications. I learned the importance of this the hard way when I had to start hiring other developers.
CakePHP
Some popular PHP frameworks are CakePHP, CodeIgniter, symfony, and Zend.
10. Connect with Other PHP Developers
You don’t know it all. And even if you think you do, there are thousands of others out there that know how to do something better than you do. Join a PHP community likePHPDeveloper and interact with others. By connecting with other developers, you’ll learn better ways of doing the things you’re currently doing.
 Many thanks: http://sixrevisions.com

36 comments:

  1. Now I know my lapses. It really takes me days to figure out my errors. Thank you for giving me an idea.

    ReplyDelete
  2. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.

    white label website builder

    ReplyDelete
  3. They still have option to work with XML form of data. The programmers can parse the XML data more efficiently by using regular expression instead of DOM manipulation.
    plakatų spausdinimas

    ReplyDelete
  4. That was an insanely valuable blog post! Please keep and continue your good work ,Keep posting these type of interesting articles.This post is very helpful.I have been examinating out some of your articles and it’s pretty clever stuff.I need to thank you for this wonderful Article and aslo Thanks for this valuable information and all the guidelines you provided.

    ReplyDelete
  5. Well, PHP being the most common language for website development has covered a big market area. The post is very much helpful for huge number of developers out there. These must know facts must be known by every PHP developer.

    ReplyDelete
  6. PHP software engineers regularly use special cases or * to keep the SQL questions minimal and straightforward. In any case, the utilization of special cases may influence the exhibition of the web application legitimately if the database has a higher number of sections.Why use Laravel

    ReplyDelete
  7. In the technical world, creating a first impression for the E-commerce store is the important thing for getting the customer hooked with the site. The post you have shared here is very informative and work on the areas we don’t consider.
    Hire Cake Php Programmer
    Hire Phonegap Developer
    Dedicated Wordpress Developer
    Hire Dedicated Laravel Developer
    Hire Cake Php Developer

    ReplyDelete
  8. This was really an interesting topic and I kinda agree with what you have mentioned here! marketing websites

    ReplyDelete
  9. One definition proposed by the Foundation for a Free Information Infrastructure is that a software patent is a "patent on any exhibition of a PC acknowledged by methods for a PC program".
    https://www.apkmacpc.com/itools-crack/

    ReplyDelete
  10. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

    ReplyDelete
  11. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

    ReplyDelete
  12. Hey! Finally we are launch 150+ High DA Dofollow White Hat Manual SEO Backlinks here! Order Now and Boost your website ranking.

    100% Google Indexing White Hat Manual SEO Backlinks

    Thank you!
    DigiPeek

    ReplyDelete
  13. It is really a great and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us informed like this. Thank you for sharing.
    PMP Training In Hyderabad

    ReplyDelete
  14. Thanks for posting this info. I just want to let you know that I just check out your site
    rocketman denim jacket

    ReplyDelete
  15. Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also shre the related Movies,Gaming, Casual,Faux Leather and Leather materials available Raiders White Jacket

    ReplyDelete
  16. Pretty good post. I have really enjoyed reading your blog posts.Any way Here I am Specialist in Manufacturing of Movies, Gaming, Casual, Faux Leather Jackets, Coats And Vests See Kevin Hart The Man from Toronto Jacket

    ReplyDelete
  17. You're doing good! I really enjoy this article because it's very knowledgeable and informative. thanks for posting this information.


    Togel Hari Ini
    Togel Online Indonesia
    Togel Online Terpercaya
    Situs Togel Indonesia
    Situs Togel Terpercaya

    ReplyDelete
  18. First time when I learn php, I looks so hard. But after some days its become so cool.

    Gypsum Board Design is a important subject to make attractive your house. Décor your house hire JK Gypsum Decoration.

    ReplyDelete
  19. To give your interior design the best lighting possible, consider painting your walls white. Darker colors tend to absorb the beautiful light coming into your home. White walls, on the other hand, will help reflect that natural light throughout your home, giving the entire interior a real sense of drama. And JK Gypsum Decoration is the Gypsum Interior Design Firm Bangladesh

    ReplyDelete
  20. PHP Developing is a most demanding path to build up a career.

    Ecotechnology is the best environmental Inspection Company in Bangladesh. They provides their client best inspection services.

    ReplyDelete
  21. You said that great thing in your blog, I really appreciated this one, here is The Tomorrow War Jacket

    ReplyDelete
  22. I really enjoyed reading your articles. It looks like you’ve spent a lot of time and effort on your blog Dolph Ziggler DZ Logo Jacket

    ReplyDelete
  23. Your blog contains lots of valuable data. It is a factual and beneficial article for us. Thankful to you for sharing an article like this.PHP Development

    ReplyDelete
  24. I must say that you are my favourite author. You always bring surprised things for me everytime I see your articles. Great efforts!! Def Jam Varsity Jacket

    ReplyDelete
  25. You have done good work by publishing this article here.Php Development Company USA I found this article too much informative, and also it is beneficial to enhance our knowledge. Grateful to you for sharing an article like this.

    ReplyDelete
  26. I am visiting to this blog post, black friday sales my friend share me a link and i read whole blog post and find every kind of knowledge that was looking over the year.

    ReplyDelete
  27. Buy a high-performance Engine Water Pump Engine Water Pump, 6205-61-1202 for Komatsu Excavator PC60-7 PC130-7 PC130-8 Engine 4D95LE at MyMRO. View more details about MyMRO Engine Water Pump 6205-61-1202 for Komatsu Excavator PC60-7 PC130-7 PC130-8 Engine 4D95LE.

    ReplyDelete
  28. Nice post thanks, the beginner can easily start their carrier with PHP.
    Buy Microsoft Office 2019 for Mac and manage your documents easily.

    ReplyDelete