Excellent PHP programmers should at least understand the advantages and disadvantages of PHP code)

Source: Internet
Author: User

When I was an interviewer at SitePoint, I was certain to ask: What do you think are the advantages and disadvantages of PHP code? This problem gives me a general idea of the type of programmer the applicant is, rather than simply understanding his understanding of PHP functions (this Zend PHP certification is doing well, yahoo's PHP programmer interview questions also fall into this category ). What's important is that this question allows me to know if a candidate has experienced such a thing-getting a piece of messy code from a lazy programmer for reuse, you can also help other members in the team to handle such tasks.

It is true that I have no satisfactory answer to this question, but I know what answers I want to hear:

Excellent PHP code should be structured. Code segments should be divided into functions or methods, and comments should be added to the inconspicuous code segments so that they can be used clearly in the future. In addition, we should try our best to separate front-end Code such as HTML, CSS, and Javascript from the program. The object-oriented programming feature of PHP can help programmers sort the code well.

Excellent PHP code should be standardized. Whether it is to set the naming rules for the variable name and function name, or to standardize some reusable processes such as database operations and error handling, or to define how the code is indented, these normalization can greatly improve the readability of the Code.

The excellent PHP code should be adaptive. PHP has many features such as magic quotes and short tags. Opening and closing of these features will affect the running of the program. Therefore, a good programmer should add appropriate statements in his code so that the program can be adjusted according to the environment.

Good PHP code should be safe. Although PHP is an efficient and flexible language without a fixed framework, it leaves the security issue to programmers. A deep understanding of potential security vulnerabilities, such as XSS, CSRF, code injection, and character encoding loops, it is crucial for today's professional programmers.

When the applicant answers these questions, I can clearly know whether to hire him. Of course, sometimes programmers cannot clarify this issue well, and we will ask them to perform some PHP tests. Many problems in the test seem simple on the surface, but it also gives the candidates a chance to show themselves, because they can find problems as long as they observe carefully.

The following section of the "poor" PHP code is a simplified test question. This is like a question: how do you optimize this code?

The main problem with this Code is that it directly displays the data submitted by the user on the webpage, resulting in an XSS vulnerability. There are actually many ways to fill this vulnerability. So what code is what we want?

This is the minimum requirement. The XSS vulnerability is filled by the htmlspecialchars function, thus blocking invalid characters.

The person who can write this code should be the one I want to hire:

Unfortunately, few programmers can give such satisfactory answers. It took us three months to recruit programmers who satisfied us.

So how do you answer the question raised at the beginning of the article? What do you think are the disadvantages of PHP code? What qualities do you think a PHP programmer should possess?

Related Article

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.