10 things to be aware of when learning and using PHP

Source: Internet
Author: User
Tags php framework

More than 1 reading manuals and source code

There's nothing more to emphasize than reading a manual – You can learn a lot of things just by reading a manual, especially a lot of functions that have a string and an array. 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. The handbook is your friend. In addition, there are many open source programs that are developed using PHP. Why not 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 Code

Good 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 specifications

Good 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 Code

Good 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 Code

Good PHP code should be safe. The PHP5 provides excellent performance and flexibility. But the security issue lies entirely with 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 comments

Code comments are an important part of your code. Code comments can tell what the variable or function does, which will be useful in future code maintenance.

7 use single quotation marks instead of double quotation marks

strings 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 Escaping string output

It 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 commas

Use the Echo statement to output a string separated by commas (,), rather than using the string join operator (.). Performance is better.

10 output pre-check the value of the transmitted

Check the value passed before output $_get[' query ']. You can use the Isset or empty function to check whether a variable is a null value.

10 things to be aware of when learning and using PHP

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.