For large systems PHP Why is it unpleasant _php tutorial

Source: Internet
Author: User
Tags php template
I have been working on the development of PHP applications for the past four years. PHP is really easy to write. But PHP also has some very serious flaws.

Below I will give my reasons why PHP is not suitable for larger sites than small amateur sites.

1. Bad support for recursion
Recursion is a mechanism by which a function calls itself. This is a powerful feature that makes some complex things very simple. One example of using recursion is a quick sort of quicksort). Unfortunately, PHP is not good at recursion. Zeev, a PHP developer, said: "PHP 4.0Zend" uses a stack of dense data instead of using heap methods. This means that the number of recursive functions it can tolerate is significantly less than that of other languages. "See Bug 1901. This is a very bad excuse. Each programming language should provide good recursive support.

2. Many PHP modules are not thread-safe
A few years ago, Apache released the 2.0 version of the Web server. This version supports multithreaded mode, in which a part of the software can run multiple simultaneously. PHP's inventor says the core of PHP is thread-safe, but non-core modules are not necessarily. But 10 times there are nine times you want to use this module in a PHP script, but this makes your script unsuitable for Apache multithreaded mode. This is also why the PHP team does not recommend running PHP in the multithreaded mode of Apache 2. Poor multithreaded mode support makes PHP often considered one of the reasons Apache 2 is still not popular.

3. PHP is crippled for commercial use
By using caching, PHP's performance can be spiked 500%[see benchmark]. So why is the cache not built in PHP? Because zend--php's maker, it sells its own Zend Accelerator, so of course, they don't want to abandon their commercial products this piece of fat.

But there is another alternative: APC. Zend later launched Zend Optimizer, free accelerator-translator)

4. No namespace
Imagine someone making a PHP module to read a file. A function in the module is called read. Then another person's module can read the Web page, 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're going to use.

But there is a very simple solution, that is the namespace. It was suggested that PHP5 be added to this feature, but unfortunately he did not. Now, without namespaces, each function must be prefixed with a module name to avoid name collisions. This causes the function name to be long, for example Xsl_xsltprocessor_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 are from UNIX and C languages. Some other programming languages use this standard, but strangely enough, PHP has its own set of completely incompatible date format characters. In C, "%j" means the day of the year, in PHP he represents the day of the one month. What makes things more confusing, however, is that the strftime and date_format functions of Smarty, a popular PHP template engine, use C/unix formatted characters.

6. Confusion of licenses
You may think PHP is free, and all of 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. But both of these are commercially licensed. So, every module you use, you have to make sure that you agree to his license.

7. Inconsistent function Naming conventions
Some function names are made up of multiple words. Generally there are three kinds of word combinations of habits:

Direct splicing: Getnumberoffiles
Separated by underscores: get_number_of_files
Camel rule: Getnumberoffiles
Most languages choose one of them. But PHP is used.

For example, if you want to convert some special characters into HTML entities, you will use the function htmlentities to stitch the words directly. If you want to use the opposite function, you have to use its penis html_entity_decode. For some special reason, this function name is delimited by an underscore word. How could this be? You know there's a function called Strpad. Or is he str_pad? Every time you look at what the symbol is or just 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 bad because two of them are used at the same time they look different and confuse the reader.

8. Magic Quotes of Hell
Magic quote) can protect PHP scripts from SQL injection attacks. This is good. But for some reason, you can turn this configuration off in php.ini. So if you want to write a flexible script, you always have to check whether the Magic reference is on or off. Such an "attribute" should make programming easier and in fact become more complex.

9. Lack of a standard framework
A growing web site does not have an overall framework and will eventually become a maintenance nightmare. A framework can make a lot of work easier. Now the most popular framework model is the mvc-model, where the presentation layer, business logic, and database access are separated.

Many PHP sites do not use the mvc-model. They don't even have a frame. Even now there are some PHP frameworks at the same time you can write your own, about PHP articles and manuals do not improve the framework of a word. At the same time jsp-developers use. Net as a framework for struts and ASP developers, it seems as if these concepts are widely understood by PHP developers. This explains how much PHP is actually more professional.

Summary: What is the problem?

For very small projects, it can be a very satisfying programming language. But for larger and more complex projects, PHP is showing his weaknesses. As you continue to grope, you will find solutions to some of the problems I mentioned. So, when the solution is known, why can't we fix him? And why are these patches not mentioned in the manual?

The popularity of an open source language is a good thing. But unfortunately, it is not a great language. I hope all the problems can be solved one day, maybe in PHP6? ), and then we will have an open source language, which is open source and useful.

By now, when you start a project with more than 5 script pages, you might want to consider c#/asp.net or java/jsp or maybe Python is also a better choice.

After I wrote this article, some people told me some other similar articles:
Experiences of Using PHP in Large Websites
"PHP in contrast to Perl"
I Hate PHP
PHP annoyances


http://www.bkjia.com/PHPjc/589777.html www.bkjia.com true http://www.bkjia.com/PHPjc/589777.html techarticle I have been working on the development of PHP applications for the past four years. PHP is really easy to write. But PHP also has some very serious flaws. Below I will give my reason why ph ...

  • 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.