PHP Ten good development habits let you change the god of minutes

Source: Internet
Author: User
Tags php framework
this post was finally edited by wheat and wheat on 2015-5-11 16:08

1407901013l587645792.jpg (20.17 KB, download number: 5)

Download attachments

PHP Development Habits-Wheat Academy

2015-5-11 16:04 Upload

As the saying goes, the details determine success or failure, develop good habits, will be in your success on the road has a great benefit. The following small series summed up the 10 php great God's good habits, learn and turn it into their own habits, let you divided into minutes to become greater God.
1, read more manuals and source codeThere's nothing more to emphasize than reading the PHP development manual, and you can learn a lot by reading the manual, especially with a lot of functions about strings and arrays. There are many useful functions included in these functions, and if you read the manual carefully, you will often find that in the past project development process, many times you are "reinventing the wheel", and in fact you just need a core function to complete the corresponding function. In addition, there are many open-source programs that use PHP development, why not to study and learn from it? Download a source code for an open source PHP application and read it carefully. Perhaps the larger the project is worth reading, although they may have more complex structures and systems, but there are also more detailed explanations of the document.
  2, writing Modular codeGood PHP code should be a modular code. PHP's object-oriented programming features are particularly powerful tools that can break down your application into functions or methods. You should separate the front-end HTML/CSS/JAVASCRIPT code from the server side of your application as much as possible, and you can follow the MVC (model-View-controller) pattern on any PHP framework.
  3, code writing specificationsGood PHP code should have a complete code-writing specification. By naming the variables and functions, a unified approach to accessing the database and handling the errors, and the same code indentation, and so on to achieve the programming specifications, so that your code can be more readable.
  4, writing Portable codeGood PHP code should be portable. You can use PHP's existing features, such as magic quotes and short tags. Try to understand your needs and then write code that is independent and portable by adapting to PHP features.
  5, writing security CodeGood PHP code should be safe. PHP5 offers great performance and flexibility, but security is all about developers. For a professional PHP developer, deep understanding of critical security vulnerabilities is critical, such as cross-site scripting (XSS), cross-station request forgery (CSRF), Code injection vulnerability, and character encoding vulnerability. By using PHP's special functions and functions, such as: Mysql_real_escape_string and so on, you can write safe code.
  6, code commentsCode comments are an important part of your code. Code comments can tell what the variable or function does, which is useful in later code maintenance.
  7, using single quotation marks instead of double quotesstrings always use single quotes instead of double quotes to avoid performance degradation caused by variables within the PHP search string. Using single quotes instead of double quotation marks to contain strings can be faster. Because PHP searches for a variable in a string surrounded by double quotes, the single quotation mark does not.
  8, escape string OutputIt is a good practice to use ent_quotes as a parameter to pass to the Htmlspecialchars function to ensure that single quotation marks (') are also converted to HTML entities.
  9, separating string output with commasUse the Echo statement to output a string separated by commas (,), rather than using the string join operator (.). Performance is better.
  Ten, output pre-check the value transmittedCheck the value passed before output $_get[' query ']. You can use the Isset or empty function to check whether a variable is a null value.

PHP Development Program Ape, do you all understand? Understand the collection, to the big God on the line ~ ~

Recommended Learning: PHP video Tutorial (http://www.maiziedu.com/course/14/) Article source: Web Developer
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.