Speaking of the "five major damages, comprehensive analysis of the poor design of PHP ",

Source: Internet
Author: User
Tags autoload php editor scream what php ultraedit zend framework
Source: www. oschina. netquestion57579_501_www.oschina.netquestion1579_000062. I think about it in the middle of the night. I thought about it before, after, when I decided to delete my blog account yesterday afternoon. Open the computer, open OSC, and see that sweet potato is already updating various OSC news

Source: http://www.oschina.net/question/57579_50368 http://www.oschina.net/question/1579_49262. I think about it in the middle of the night. I thought about it before, after, when I decided to delete my blog account yesterday afternoon. Open the computer, open OSC, and see that sweet potato is already updating various OSC news

Source: http://www.oschina.net/question/57579_50368


Http://www.oschina.net/question/1579_000062.

Introduction

I had a stomachache in the middle of the night and thought about it during my restroom. I tried to delete the blog account yesterday afternoon.

Open your computer, open OSC, and you will see that sweet potato has started updating various news about OSC, including some aftermath of the incident. during the whole process, sweet potato did not leave any messages to me, I have not sent me any emails, so I can see his position. I think I have done the right thing for my decision to delete the number.

The beginning and end of the incident lies in the article "poor PHP design for comprehensive analysis of five major damages". In my opinion, this is a very unprofessional article, I believe that some other users, including Hong Ge, who do not agree with this Article, will feel the same way. The article conveys some information. Unfortunately, even people like sweet potato did not see it. Of course, he did not understand it because he had never used PHP development projects, take it for granted. First, the information includes:

1. the problems mentioned in the article lack objectivity and arguments.

2. He complained about some features of PHP and did not go to the official documents.

3. The author is a nervous person, which can be learned from the first sentence of the opening: "My temper is strange. I will complain a lot. I don't like most technologies on this planet. ". Echo the end of the article: "If you are interested in learning other things only in PHP, you can look at the Python tutorial." Obviously, the author prefers PHP and Python. The first sentence in the beginning is "I don't like most technologies on this planet", so he doesn't like Python either. Sooner or later, he also sprayed Python with the same attitude.

It is better to believe in books than to have no books, but unlimited doubts. Basically, this person knows nothing, he is not proficient in anything, and he knows nothing, and then he is spraying, for such a person's point of view, it is best for the onlookers to wear rational glasses. Otherwise, they will be taken astray, but they cannot rely on the ulterior motives of those who post such articles.

The starting point of writing this article is to avoid this result of going astray. An additional intention is to strongly accuse sweet potato and OSC of being unprofessional.

PHP model-pragmatic

The earliest production of PHP aims to quickly modify the content of the webpage. The PHP design, in fact, is based on the implementation level of PHP. Compared with Ruby and Python, PHP is really poor and lacks foresight, and long-term planning.

Without a general picture, PHP gradually loses its direction and market. Then, the Zend business team joined the PHP core, added the Zend Engine to PHP, and used the Zend API to reconstruct the PHP core, this gives it a longer-term development prospect, increased scalability, and solved some of the problems PHP was criticized at that time. In fact, PHP is more embarrassing than any development language in the world. This embarrassing superficial phenomenon is that the father of PHP does not have a very deep and professional computer theoretical foundation, and the language of PHP almost cannot reflect any programming philosophy of "progress" and "avant-garde. At the same time, as an open-source project, the core Zend Engine is supported by a commercial organization.

Compared with various popular languages, C, C ++, C #, Java, and Scala, these languages are first supported by academic theoretical research, such as Python, Ruby, and Javascript, it also integrates various advanced programming features and unique programming philosophy. PHP stands in front of them, and it is like a gnore with a congenital disability.

From the earliest C-style functions, this is a function that every PHP programmer must deal with every day and must be used for daily work. To the C ++ style conversion, a batch of static classes, and the Class model of PHP 4 to PHP 5 during the transition period. And the subsequent Java-like style, a large number of instantiated classes, SPL standard interface classes, and so on.

I am new to PHP 5, so I don't know what happened before. For me, no matter what style it is, it is just an API. However, I would like to focus on the changes to the features of PHP 5.3 and 5.4 versions.

One of the major features of PHP 5.3 is the support of namespace and closures. In the Pear specification, PHP namespaces use _ for separation (also including the Zend Framework 1 package specification). For example, zend_Http_Core: physical path mapped to Zend/Http/Core. php, and Core. the ClassName in php should be: class Zend_Http_Core.

One of the biggest problems is that such a class name is too long, which will lead to many problems and will not be described here. Secondly, this naming mechanism cannot solve the need for rapid project reconstruction. For example, an existing project has encapsulated a String class. It may be necessary to completely reconstruct this Class based on customer requirements, however, there are a lot of existing code and there is a lot of new String problems. You have almost no starting point to rewrite a ClassName point. For example, if I restructured the String class and changed it to Jan_String, then all the code, you need to search and replace a large number of original String keywords.

The namespace mechanism of PHP 5.3 provides you with a class rewrite solution through the lowest performance loss. The new String class is reconstructed using namespace, Jan \ String, in all files that use String, declare use Jan \ String as String to solve all the problems.

At the same time, this namespace mechanism supports the autoload API. Even if you do not require or include any files, if you implement the autoload interface, when you call use Jan \ String, the system automatically calls autoload back to load the related libaray. If your autoload encapsulation does not support this mechanism, you only need to slightly modify your implemented autoload interface, then all the problems will be solved.

At the same time, it was really painstaking for the PHP team to select the namespace separator, because they had tried to introduce the namespace mechanism as early as the php 5.2.x period. At that time, the implementation was a mechanism similar to Java package, and finally gave up the solution. Because a core issue associated with namespace is how to quickly associate related files from the file system. keyword, such as Jan. the replace operation is still required for a fullname such as String. However, if you use \, you do not need to convert it on Windows or Unix systems to use it directly. Here we can see that the PHP team is thinking about the namespace solution.

As a matter of fact, another function in php is also painstaking, namely, the realpath function. This function can convert any path name to the path name specified by the current system, such as/srv/www/abc. php. on a Windows server, it will naturally convert it into \ srv \ www \ abc. php. After arriving at PHP 5.3, this function not only converts the path name, but also determines whether the path name exists (not supported by BSD, I have actually tested Linux and Windows ). After 5.3, the query results of this function will be cached (is_file and file_exists are the same). At the same time, two underlying functions are added to query related cache results.

PHP 5.4, I think the biggest feature update is the introduction of trait and built-in web server. As mentioned above, when selecting the Class instantiation mode, PHP selects the Java mode and the single inheritance mode. After declaring a large number of classes, there is a common problem: you cannot flexibly expand a Class that has inherited from a parent Class. The mixin Implementation of php is available in a variety of strange modes, which are implemented using the _ call interface and dynamic file loading.

This trait is no stranger to me. It has long been used in Scala. Trait looks more like a mix-in mechanism in Javascript (adding an object to another object), but he does not declare an additional Class, and his design goal is to use it together.

By explaining the small details of php 5.3 and 5.4 updates, I aim to explain that the PHP team is a very pragmatic team, you can see from his selection of update features. In fact, I have been very concerned about the todo list of php 5.4 in a certain period of time, which describes many new features (proposed by the user), including trait, built in server, automatic packing, and so on. The feature they choose to implement is often a small change in actual programming needs, but it allows developers to quickly expand the programmable range and improve the convenience of development updates.

This also includes another feature, that is, full emphasis on PHP performance. PHP5.2 to 5.3, and 5.3 to 5.4 are all mentioned again. It further improves performance and solves a key problem that the previous version affects performance. This also fully demonstrates the practicality of the PHP team.

I think it is funny to address the problems caused by PHP language updates complained by the author of the original article. The static language, regardless of whether it is a specific article, for several common scripting languages, the upgrade of Ruby and Python does not have to worry about the old version, if you do not want to talk about Python, choosing the correct version is the first step to learn Python well. Otherwise, you will be unable to implement your Python skills. Ruby on Rails was not supported in Ruby 1.9 for a long time. I don't know how it works. Javascript, because developers widely use a basic version, the current implementation version in the browser is always that version. Don't talk to me about what browser supports and what new specifications, and talk to your customers.

In contrast, PHP is so simple that it keeps releasing new versions and constantly tries to bring convenience, practicality, and performance to old users without making too many changes, the premise is that you are actually developing in PHP mode.

Speaking of the PHP mode, there is actually some ambiguity. What is the PHP mode? No, actually no. However, it does exist, that is, pragmatism. It can be used as an example to describe the object orientation or the aunt. But the premise is that you really understand what PHP is doing and why it is.

Inconsistent naming Style

This is a problem most people will mention when criticizing PHP.

For example, if we compare the naming rules with those in Java, the PHP naming style is really disgusting. However, this is just a problem. Do you know what the JDK compiler actually converts your Java code? You don't know, you just took the box that JDK provided to you to fix it, so that your mind can think everything should be like this. In addition, this mode is constantly being strengthened, especially what frameworks are well-known under the several Java (I am not even too lazy to remember their names ), then Baba said that he would do that and the result was nothing. Without the framework or Java, It is a fart.

In comparison with C #, C # is a very Open language. Note that this Open language does not refer to it. It refers to its ability to absorb various new things and features. When Java becomes popular, VB and ASP are lost, and C # And. net are used. When Ruby and Python get angry, they create various script engines (which Iron or something doesn't know yet) and introduce the script feature to C #. Flash and ActionScript are on fire, so we can build a SliverLight. Scala came out, and he also introduced the generic into C. However, if he does something like this, he will never tell you what he has done at the bottom layer (maybe C # has made the bottom layer public now. I don't care about it or want to know it ).

Well, when I look at the above section C #, I don't have to tell you the fact that I gave you a set. In fact, Microsoft has objective requirements to do this, instead of being greedy, you just don't understand it. I don't know much about it.

In contrast, PHP's Zend Engine is standardized, known, and scalable. For example, many opcode cache extensions, such as XCache and apc, and Zend's own commercial extensions. Each PHP source code we downloaded contains the source code implemented by Zend Engine. In China, Zend API, Zend Engine, and PHP Core are all described in detail in articles such as snow bird and fat bird. Snow bird even lists the Zend Engine compilation instructions in detail.

Why are you jealous of PHP users? Comparing Java with C #, PHP adopts the standard Open Source Path. You have the stuff that C # and Java give you. Come and enter it here. What do you know about the underlying things of Java and c? Or do you use C to write a set of skills?

Digress: There is a language called kuaishou in China that exposes windows APIs and allows developers to quickly develop and use some Windows tools. I have actually learned about this language and actually made some gadgets. I really think this set of things is quite good, at least more interesting than the Windows SDK. I really feel very strange to those who yell at kuaishou. You are so powerful, why didn't you look at what you did? You can encapsulate and expose Windows APIs, but is it qualified to say that what others are doing is spam?

I complain about PHP developers. How seriously have you read the PHP underlying implementation code? How many people have actually tested and used the features updated in major PHP version upgrades? The so-called PHP mode does not exist at all. You need to read more PHP documents and pay more attention to the PHP wiki.

There is another saying about the inconsistent style. How many people are actually developing PHP using notepad to write code? No, right? Even if Notapad ++, editplus, Ultraedit, VIM, and so on, this editor intelligently prompts 90% of PHP keywords and common functions, especially VIM and Ultraedit (editplus I don't use much, you can customize the keywords and functions you need. I believe that most new PHP users will definitely choose to use IDE, such as PHP Storm, Netbeans, Eclipse PDT, Zend Studio, PHPDesigner, PHP Editor, etc, it is updated almost synchronously with the PHP version. With smart tips, I really don't understand any complaints about Scala, C, and C ++ as a PHP developer.

In addition, PHP documentation archiving has always been closely integrated with PHP version updates. php chm is updated in almost every phase. For Java document libraries and MSDN, PHP documents are far more practical than they. The PHP document details the function purpose, the role of the parameter, and which parameter is the reference type. When using this function, you need to pay additional attention to what happens and what new features are added to each version, A simple example (there will be more than one demonstration of some important functions and classes), and the description of the Class is more detailed with the update of PHP 5.3.

Don't look at PHP in any Java or C # format. They won't tell you how they do it. They can only set one frame after another for you. We should not look at PHP from the perspective of Ruby or Python. They are cutting-edge and cutting-edge. They still have many problems to solve and cannot solve.

PHP is PHP.

"Nitpicking"

> PHP does not hesitate to keep moving forward. Nothing is better.

I have already said this in my previous remarks, and I don't want to explain it any more. If I still feel that this is indeed a problem, I will say, you should not use PHP.

> This is not a correct design principle. Early PHP versions were affected by Perl. for a large number of standard libraries, refer to C using the "out" parameter. For OO parts, the design is like C ++ and Java.

This is an issue of historical development and is caused by ensuring compatibility before and after. At the same time, Java is just the specification you seem to have, and you don't know what it actually does (the implementation of the compiler is not so idealistic ). One of the most important issues is pragmatism. For example, if fopen is finished, why should he delete or change his name to make it look comfortable? Unless you are idle.

> PHP introduces a lot of inspiration from other languages, but it is still hard to understand those familiar with other languages. (int) It looks like C, but int does not exist. namespace use \. the new array syntax uses [key => value], which is different from the definition of the hash literal in any other language.

I will not mention this either. I have already mentioned some, but the type issue will be mentioned later.

> Weak types (for example, automatic conversions between strings/mumbers/) are so complicated.

The type matching problem may not only exist in PHP, but also in Java.

> A small number of new features are implemented using New syntaxes. Most work is done by functions or something that looks like a function. Apart from class support, new operators and keywords are required.

I would like to ask which language is not updated like this? If you are so picky, I would like to say that you should not be a programmer. You should play with your own fingers.

> All the issues listed on this page have official solutions-if you want to support Zend to fix their open-source programming languages.

So far, I think Zend has made it very clear to distinguish between commercial and open-source fields. The minimum difference is that you can see the Zend Engine code, A large number of products can replace Zend commercial products. The Pecl extension library of PHP itself is also quite active, far better than the commercial products of Zend itself.

> There is a long way to go. Think about the code below and pick it out from somewhere in the PHP document. What will it do?

Open a file handle by mistake. What is this? The author wants to say that he is puzzled. You should read the scala underlying code. I think you are going to commit suicide.

> If PHP uses -- disable-url-fopen-wrapper for compilation, it will not work ?)
> If allow_url_fopen is disabled in php. ini, it will not work. (why? Unknown .)

The two are disabled in the new version. In fact, PHP wiki has already explained in detail. If you don't see them, I don't want to tell you why.

> The warning for @ and non-existent file will not be printed.

The purpose of error suppression is to quickly solve some practical problems. In fact, you can use is_file () and then throw an error. Which language does not do this? If you complain that no error is thrown here, I want to say that you are actually 2. You don't need @ at all. Why are you using it? Are you ill?

> But if scream. enabled is set in php. ini, it will print again.

> Or if you use ini_set to manually set scream. enabled.
> However, if the error_reporting level is not set, it is different.

Php. ini settings, any team, or individual, using a PHP developer, will definitely choose a fixed php. ini, who can switch the server's php. is ini a joke? Php. ini only provides you with a configurable environment. You can choose a development mode based on your configuration habits. You can decide whether to suppress the error or report the error, what are the complaints? Are you using Java for development? JDK 1.6 and JDK 1.7, 32bit and 64bit later? If you have the skills, you yell at Microsoft. You are ill. Integrate so many features into C #.

> The language is full of global and implicit statuses. mbstring uses global character encoding. func_get_arg looks like a normal function, but only operates on the function currently being executed. error/exception handling is global by default. register_tick_function sets a global function to run each tick (Hook ?) ---- What ?!

I think this is all about neurology. Similarly, you can set a default php environment, and then do it based on your actual needs. If you fully know what you want to do and what you want to do, you can ignore most of the things you don't like.

> There is no thread support. (Not surprising, because we have provided.) In addition, the lack of built-in fork (as mentioned below) makes parallel programming extremely difficult.

In CGI Mode, PHP threads are not included in PHP programming. This process also simplifies a lot of things. PHP needs thread support rather than other threads. I really don't think that the functions to be implemented by those who close their mouths and talk about threads really have to be implemented by threads. Besides, you can use C \ C ++ to call PHP. What's the problem?

Besides, the Pecl library has libevent encapsulation. Do you know?

> Json_decode returns null for incorrect input. Although null is a legal JSON decoded object, this function is extremely unreliable unless json_last_error is called every time you use it.

I have been using the json_decode function for many years and have hardly encountered any problems. It restricts input and output. This is a kind of golden rule that the Web itself must strictly implement. Here you complain about the incorrect JSON parsing, have you checked the input and output? Why is json_decode abnormal. This is the fundamental solution to the problem.

> If it is found at location 0, array_search, strpos, and other similar functions return 0, but if none are found, false is returned.

This is really a full display, you are not good at looking at the document. 0 indicates that it matches from the starting position, and false indicates that it is completely mismatched. You may not read the document well or understand the difference between = and =. strpos () = false. You must have an accident. You can't blame anyone for learning a language without reading documents.

> In C, functions such as strpos return-1, if not found. if you do not check this situation and try to use it as follows, it may hit the junk memory and the program will crash. (maybe, this is C. who knows. i'm sure there are at least tools to handle it)
> In Python, the equivalent. index Method throws an exception. If the element is not found, the program will crash if you do not check the situation.
> In PHP, this function returns false. if you use FALSE as the subscript or use it to do other things, PHP will silently convert it to 0, except for =. the program will not crash; it will execute the wrong logic without any warning, unless you remember to include the correct sample code in every place using strpos and other similar functions.

Why don't you talk about it? What eq and shit functions should be used in Java to check whether two objects are equal? This is how to spoof and silly Q.

Every language has its own mode. Since you know C and Python, you still complain about PHP. This is simply because you despise PHP, but you have not taken a serious look at the document. No PHP tutorial says that PHP mainly uses the C mode, but it is just your own subjective judgment.

> "Foo" = TRUE, and "foo" = 0... but, of course, TRUE! = 0.
>>== The two sides are converted into numbers. If possible, this means that it will be converted to floats if possible. therefore, a large hexadecimal string (for example, password hashes) may be compared to true by chance, even though they are different. even JavaScript does not.
> For some reason, "6" = "6", "4.2" = "4.20", and "133" = "0133". But pay attention to 133! = 0133 because 0133 is octal.
>>== Comparison value and type... except for the object, only the two sides are actually the same object. true! For objects, = compare values (or each attribute) and types, which is === compare any non-object type behavior. Is it fun?

The operator problem. PHP is a special case, but none of the languages can solve the = and = problems. All you have to do is understand, test, and so on. It's strange that it won't solve any problems.

As long as you remember the same thing, ==== is a strict type check, and the type is not a Class. Strictly speaking, PHP, Java, and C # Are all type-oriented and disguised as object-oriented. If you cannot figure out the orientation and object orientation, don't blame this problem. Therefore, PHP, Java, and C # may be equally poor in terms of processing these issues.

> [] Subscript operators can also be spelled {}.

> [] Can be used for any variable, not only strings and arrays. It returns null without error warning.
> [] Can only obtain a single element.

The Recommended Practice in the official documentation is []. You may need to use {}. I can't help it.

If [] does not exist, an error is returned. null is returned and no error is returned because an error is returned when it is disabled.

I can only use a single element, not just PHP. What can I say?

> Foo () [0] is a syntax error (fixed in PHP 5.4)

This is a question of language feature support, not a syntax error. C #, Java, and PHP also have a lack of static class inheritance issues, but PHP has added support for static keywords. I don't want to explain it to anyone I don't know.

> Unlike (literally) Similar operators in any other language ,? : Is left-bound. Therefore:

Isn't it easier and easier to use a switch? Are you writing this in order to be elegant or to prove that you are awesome?

> The variable cannot be declared. When used for the first time, a non-existent variable is created as a null value.

In most tutorials, we recommend that you use a variable to initialize a variable first. I recommend that you use isset () as a variable to make your code more secure.

> Before using global variables, you must declare global variables. this is based on the above natural results, so this is a perfect reason, but if no declaration is displayed, the global variables cannot even be read-PHP will quietly create a local variable with the same name to replace it. I have never seen other languages use similar methods to solve scope problems.

I do not understand the installation, do I?

1 $GLOBALS['abc'] = 123;

2

3 function test() {

4 global $abc;

5 unset($abc);

6 }

7 test();

8

9 var_dump(isset($GLOBALS['abc'])); // What is output here?

This issue has been highlighted in the Zend Framework usage specification.

> Without referencing. PHP, the so-called reference is a real alias. This is undoubtedly a kind of backend. Unlike Perl references, there is no object identity transfer like Python.

I don't know how Python and Perl references, and I don't think there is any problem with PHP references.

......

......

Okay, that's enough. I really don't want to list and refute them one by one. Throughout the full text, I found the following points:

1. The author is a nervous, extreme scrubbling and nitpicking.

2. If you are not familiar with PHP, list different languages to describe PHP. However, it only means that he does not have a good description of PHP documentation.

3. The author is a narcissistic madman. Taking the only experience and experience as an example, even in C, ==and ==== should be taken with special care.

4. Since the author complained about PHP in extreme ways, I think it is better for him to learn other languages directly. Is it useful to complain?

I switched from Ruby to PHP. When I first started using Ruby, I felt that I was not used to it. But PHP is not as bad as he said, and PHP is very free. You can choose it on your own. If you select a correct mode, you can ignore what you think you do not like.

Later, I needed to use Java. I really think that Java (not JDK) is the most silly and common language in the world, but I have to install it, in particular, that layer has the same inheritance as an idiot, so I decided to use Scala instead of Java.

If you really care about the missing parts, don't use PHP. Are these useful?

Summary

I know about sweet potato. I have also read many articles from dadong. They are all experienced developers. What are level articles and Spam, I think, if they are familiar with their own language, they will be able to understand it at a glance. I think they do not understand PHP.

However, the problem is that such an article is already a hundred thousand. Many of the problems he mentioned have already fully revealed that he did not fully understand PHP, I have not read the official PHP documents well. I am not very familiar with such an article written by a dumb who is half a bucket of water, but I am shaking it to the top of my homepage, then, I would like to say to myself: Be alert to a large number of PHP developers to avoid similar errors. You are Stephen Chow. Are you funny?

At the same time, OSChina, as a comprehensive open-source solution, how much can you know about both of them? You are not familiar with PHP. Why do you want to use this article to warn PHP developers?

Also tell those replies, say what to use this shit article to do a wake-up person, go back to carefully read the PHP documentation, go back to have a good look at the PHP Wiki, snow migratory birds (http://www.laruence.com /) and fat (http://www.phppan.com/) blog are carefully look at, more meaningful than you here to follow the post.

Well, this will be my post on OSC. I will not restore all my articles on OSC. After this time, I will apply for a domain name to activate my blog, I will announce it later. If you think there is something interesting in the next article, please stay tuned.

Thank you!

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.