Home > Backend Development > PHP Tutorial > Ten good PHP development habits will make you a master in minutes

Ten good PHP development habits will make you a master in minutes

WBOY
Release: 2016-07-25 08:49:02
Original
1065 people have browsed it
This post was last edited by Wheat Maizi on 2015-5-11 16:08

Ten good PHP development habits will make you a master in minutes
As the saying goes, details determine success or failure. Developing good habits will be of great benefit to you on the road to success. Below, the editor has summarized ten PHP good habits of masters. Learn and transform them into your own habits and styles, so that you can become a master in minutes.

1, read more manuals and source code
There is nothing more worthwhile than reading the PHP development manual Things to emphasize, by reading the manual you will You can learn a lot, especially many functions about strings and arrays. These functions include many useful functions. If you read the manual carefully, you will often find that in the past project development process, you often "reinvent the wheel", but in fact you only need one core function. Complete the corresponding functions. In addition, there are many open source programs developed using PHP. Why not learn and learn from them? Download a copy of the source code of the open source PHP application and read it carefully. Perhaps the larger projects are more worth reading, although they may have more complex structures and systems, but also have more detailed explanatory documentation.

  2, writing modular code
 GoodPHPcode should be modular code . The object-oriented programming features of PHP are particularly powerful tools for breaking your application into functions or methods. You should separate as much of the front-end HTML/CSS/JavaScript code as possible from the server side of your application, you can also follow MVC on any PHP framework (Model-View-Controller) mode.

  3, coding standards
A good PHP code should have a complete set of codes Write specifications. Achieving programming standards through naming variables and functions, unified methods for accessing the database and handling errors, and the same code indentation method can make your code more readable.

  4, writing portable code
 Good PHPcode should be portable. You can use existing features of php like magic quotes and short tags. Try to understand your needs and then write your code to make it self-contained and portable by adapting to PHPfeatures.

  5、Write secure code
Good PHPcode should be safe. PHP5 offers great performance and flexibility, but the security issue lies entirely with the developer. For a professional PHP developer, it is crucial to have a deep understanding of major security vulnerabilities, such as: Cross-site scripting(XSS), Cross-site request forgery( CSRF), code injection vulnerability, character encoding vulnerability. By using the special features and functions of PHP, such as: mysql_real_escape_string and more, you can write safe code.

Code Comments are an important part of code. Through code comments, you can know what the variable or function does, which will be very useful in later code maintenance.
7
, use single quotes instead of double quotes
 Strings always use single quotes instead of double quotes to avoid PHP performance degradation caused by searching for variables within the string. It's faster to enclose the string in single quotes instead of double quotes. Because PHP will search for variables in a string surrounded by double quotes, but not single quotes.

Use
ENT_QUOTES
is passed as parameter to htmlspecialchars function to ensure that single quotes (') are also converted to
HTML
entities, which is a good practice. Pass echo statement output uses commas( ,) delimited strings have better performance than using the string concatenation operator (.).

  10、Check the passed value before output
Check the passed value $_GET['query'] before outputting . Using the isset or empty function, you can check whether a variable is null. PHP development programmers, do you all understand? Once you understand it, quickly collect it and follow the example of the master~~

Recommended learning: PHP video tutorial (http://www.maiziedu.com/course/14/)Article source: web developer
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template