Analysis of PHP language defects _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
A detailed analysis of PHP language defects. PHP language defects 1. poor support for recursion is a function calling mechanism. This is a powerful feature that can make some complicated things very simple. One uses recursion. PHP language defects 1. poor support for recursion

Recursion is a function calling mechanism. This is a powerful feature that can make some complicated things very simple. A recursive example is quick sort ). Unfortunately, PHP is not good at recursion. Zeev, a PHP developer, said: "PHP 4.0 (Zend) uses stacks instead of heaps for intensive data. That is to say, the number of recursive functions that it can tolerate is significantly less than that of other languages ." See bug 1901. This is a bad excuse. Every programming language should provide good recursive support.

PHP language defects 2. many PHP modules are not thread-safe

A few years ago, Apache released the Web server version 2.0. This version supports multi-threaded mode. In this mode, one part of the software can run multiple at the same time. The inventor of PHP said that the core of PHP is thread-safe, but not necessarily non-core modules. But nine times in ten times, you want to use this module in the PHP script, but this makes your script not suitable for the Apache multithreading mode. This is why the PHP team does not recommend running PHP in the multi-threaded mode of Apache 2. Poor multi-threaded mode support makes PHP often considered one of the reasons why Apache 2 is still not popular.

PHP language defects 3. PHP is not sound due to commercial reasons

By using the cache, PHP performance can increase by 500% [see the benchmark test]. Why is the cache not built in PHP? Because Zend-the maker of PHP is selling its own Zend Accelerator, of course they don't want to abandon their commercial products.

But there is another option: APC. (Zend later introduced Zend Optimizer, a free accelerator-translator)

PHP language defects 4. no namespace

Imagine a person created a PHP module to read files. A function in the module is called read. Then another module can read the webpage, which also contains a function read. Then we can't use these two modules at the same time, because PHP doesn't know which function you want to use. But there is a simple solution, that is, namespace. Someone suggested that PHP5 add this feature, but unfortunately he did not. Currently, there is no namespace. each function must be prefixed with a module name to avoid name conflict. This causes the function name to be too long. for example, javas_javastprocessor_transform_to_xml makes the code difficult to write and understand.

PHP language defects 5. non-standard date format characters

Many programmers are familiar with date format characters, which come from UNIX and C. Some other programming languages use this standard, but it is strange that PHP has its own set of completely incompatible date format characters. In C, "% j" indicates the day of the year, and in PHP, it indicates the day of the month. What makes things even more confusing is that the strftime function and the date_format function of Smarty (a popular PHP template engine) use C/UNIX formatting characters.

PHP language defects 6. messy licenses

You may think PHP is free, and all the PHP modules mentioned in the manual are free. Wrong! For example, if you want to generate a PDF file in PHP, you will find two modules in the manual: PDF and ClibPDF. However, both of them have commercial licenses. Therefore, you must ensure that you agree to his license for every module you use.

PHP language defects 7. inconsistent function naming rules

Some function names are composed of multiple words. There are three kinds of word combinations:

Splicing: getnumberoffiles

Separate by underline: get_number_of_files

Camel rule: getNumberOfFiles

Select one of most languages. But PHP is used.

For example, if you want to convert some special characters into HTML entities, you will use the htmlentities function (directly concatenate words ). If you want to use the opposite function, you need to use its younger brother html_entity_decode. For some special reason, this function name is separated by underscores. How can this happen? You know there is a function called strpad. Or is it str_pad? Every time you want to check what the symbol is or wait for him to make a mistake. Functions are case-insensitive, so there is no difference between rawurldecode and RawUrlDecode for PHP. This is also very bad, because both of them are used and they seem different, confusing readers.

PHP language defects 8. magic references to hell

Magic quote protects PHP scripts against SQL injection attacks. This is good. But for some reason, you can disable this configuration in php. ini. Therefore, if you want to write an elastic script, you always need to check whether the magic reference is enabled or disabled. Such a "feature" should make programming easier, but in fact it becomes more complicated.

PHP language defects 9. lack of standard framework

A growing website does not have an overall framework and will eventually become a nightmare of maintenance. A framework can simplify a lot of work. Currently, the most popular framework model is the MVC-model, in which the presentation layer, business logic, and database access are separated. many PHP websites do not use the MVC-model. They don't even have a framework. Even now, you can write some PHP frameworks on your own. The articles and manuals on PHP have not improved the framework. Meanwhile, JSP-developers use the framework like Struts and ASP developers use. net. it seems that these concepts are widely understood by PHP developers. This shows how professional PHP is.


Unsupported for recursion is a function calling mechanism. This is a powerful feature that can make some complicated things very simple. There is a recursion...

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.