Why is PHP uncomfortable for large systems? _ PHP Tutorial

Source: Internet
Author: User
Tags php template
Why is PHP uncomfortable with large systems. I have been developing PHP applications for the past four years. PHP is indeed very easy to write. However, PHP also has some very serious defects. Next I will give my reasons why PH has been devoted to PHP application development for the past four years. PHP is indeed very easy to write. However, PHP also has some very serious defects.

Next I will give my reasons why PHP is not suitable for websites larger than small and amateur websites.

1. poor support for recursion
Recursion is a function calling mechanism. This is a powerful feature that can make some complicated things very simple. There is an example of using recursion to quickly sort quicksort ). Unfortunately, PHP is not good at recursion. Zeev, a PHP developer, said: "PHP 4.0 Zend uses the stack instead of the heap method 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.

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.

3. PHP is disabled due to commercial applications
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 released Zend Optimizer, a free accelerator-translator)

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.

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 the C/UNIX formatting characters.

6. chaotic 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.

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 can use the htmlentities function to directly splice 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.

8. magic references to hell
Magic quote) can protect PHP scripts from 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.

9. the standard framework is missing
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 all 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.

Summary: What is the problem?

For very small projects, it can be a very satisfactory programming language. But for larger and more complex projects, PHP shows that it is weak. After you keep exploring, you will find the solutions to some of the problems I mentioned. So when the solution is known, why can't we fix it? Why are these patches not mentioned in the manual?

It is a good thing that an open-source language is very popular. Unfortunately, it is not a great language. I hope all the problems can be solved one day, maybe in PHP6 ?), Then we will have an open source language that is both open source and easy to use.

Now, when you want to start a project with more than five script pages, you 'd better consider C #/ASP. net, Java/JSP, or maybe Python is also a better choice.

After I write this article, some people tell me some other similar articles:
Experiences of Using PHP in Large Websites
"PHP in contrast to Perl"
I hate PHP
PHP Annoyances


Bytes. PHP is indeed very easy to write. However, PHP also has some very serious defects. Next I will give my reason why PH...

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.