What is wrong with php?

Source: Internet
Author: User
The reason for raising this question is actually that I have read the answer: what common low-level errors are there in PHP programming? Www. zhihu. comquestion... the error method mentioned in this document: When the Class is used as the namespace, the method sets the function of the Class... the reason for raising this question is that I have read this answer on Zhihu:

What are common low-level errors in PHP programming?

Http://www.zhihu.com/question...

The error practices mentioned in this document:
When Class is used as the namespace, method sets the function of Class.

What's wrong with this?

Reply content:

The reason for raising this question is that I have read this answer on Zhihu:

What are common low-level errors in PHP programming?

Http://www.zhihu.com/question...

The error practices mentioned in this document:
When Class is used as the namespace, method sets the function of Class.

What's wrong with this?

Procedural Structured programming is "ideologically solidified "? I think "object-oriented" is a perfect solution for all-around development. "You can say" things are fixed in an article ."Fully orientedProgramming requirements such as "one-size-fits-all. I think the biggest benefit of object thinking is encapsulation. it can encapsulate relevant functions and provide them to other people for calls. if there is a name conflict, just change the class name. if you do not need classes, you need to modify the prefixes of multiple functions in case of name conflicts. so there is nothing wrong with using classes as namespaces.

Let's take a look at PHP itself. PHP provides two functions: function-based and class-based encapsulation. function-based encapsulation includes common string operation functions and array operation functions, class-based encapsulation involves SPL libraries. do you say that object-oriented is more advanced and convenient than procedural approaches? I can't see it. if I am so keen on object-oriented, shouldn't I learn that all the databases are Java based on class encapsulation "fully object-oriented?

Java God Wang look at object-oriented programming:

"Object Thinking" is a good way to access data. However, "object-oriented" (with more "oriented" characters) is to put this kind of good idea into full play. Many object-oriented languages call "everything is an object" and put all functions into the so-called objects, called "methods". they call common functions "static methods ". In fact, when there is very little need for abstraction, you need to use a "method" that is embedded in the object and closely integrated with the data ". In other cases, you just want to express the transformation operations between data. these operations can be expressed using common functions, and they are simpler and more direct. Put all functions into the object is put before the horse, because the function itself is not an object, they are only a transformation operation on the object. Most functions are independent of objects and cannot be called methods ". All functions are forcibly put into objects they do not belong to, and all of them are used as "methods", resulting in overly complicated object-oriented code logic. A very simple idea. you have to go around a lot to make it clear.Many people do not know many of the advantages of the "object-oriented language" they use so far. they are inherited from procedural languages.Most object-oriented languages lack the correct mechanism for implementing first-class functions. Java is the ultimate language. it does not allow passing functions as data. You need to encapsulate all the functions into the class and call them "methods", but as I said, this is kidnapping. The lack of first-class functions is the main reason why Java requires so many "design patterns. With a first-class function, you no longer need most of these design patterns.

Personal opinions:

The biggest downside is thatThought solidificationI can't get out of the process, I can't understand what really changes object-oriented programming, where is the true advantage of object-oriented programming, let alone interface-oriented programming.

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.