In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the difference between PHP and C++, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
PHP differs from C++ in: 1. PHP is a scripting language executed on the server side, while C++ is an inheritance of the C language;2. PHP does not support overloading in C++;3. The use of abstract and interface is different;4. PHP is a weakly typed language, so PHP's polymorphism is not as obvious as C++.
Operating environment: Windows 7 system, PHP 7.4 version, Dell G3 computer.
Difference:
A type Base with a protected member variable (assuming i), its subclass Derived inherits directly from Base, and Derived has a member function func whose parameters are of type Base. Can this function access the protecte members of the Base object? Not in C++, but in PHP.
About overloading:
PHP does not support overloading in C++, redefining a function (whether the parameters are the same or different, it will lead to repeated definition errors). PHP has its own overloaded methods, and more extensively than in C++, it can overload not only functions (by using the__call() method), but also member variables (by using__get() and__set()). In C++, functions can only be overloaded, and overloaded methods are only: different parameter types, different function modifiers (const).
Abstract and interface
PHP has these two modifiers because PHP does not support multiple inheritance from a common class, so interface is used to implement multiple inheritance. Abstract classes also exist in C++, but the implementation is different, C++ uses pure virtual function to indicate that this class is abstract class, can not be instantiated alone. In PHP, you can not only use the function modifier abstract (in addition, the class must also be marked abstract) to indicate this meaning, but also use the abstract modifier to modify the class more directly to indicate that it is an abstract class. In addition, pure virtual functions in C++ are not restricted by access types, and no matter what access type, they will be treated as public; abstract functions in php cannot be declared private, that's all.
polymorphism
Because PHP is a weakly typed language, its polymorphism is everywhere, making it less obvious than in C++. For example, in PHP, the function of the base class can be regarded as all virtual, so it does not need to add any modifiers, the function of the same name in the subclass and the base class will be called dynamically, while C++ is different, if the function in the base class does not add virtual modifiers, the function of the same name in the subclass will not be called dynamically, only statically.
operator overloading
PHP does not exist, but C++ does. The emphasis is on the == operator, which in PHP can be applied to any type, even if the type does not (as in C++) write its own == overloaded function. For object comparison in PHP,== means that the attributes and values of two objects are the same, and the type is the same;PHP also has a === operator, indicating that they refer to the same object, which is very similar to Java.
final keyword
The presence of this keyword in PHP indicates that the function cannot be overridden (if it is used to modify the function), or that the class cannot be inherited (if it is used to modify the class). C++ does not have this keyword, nor can it simulate that effect.
Object assignment and copy
There are three ways to copy or assign in C++.
One is pointer assignment, p1 = &obj, which is equivalent to assignment operations in PHP and Java;
The other is memberwise assignment, which is what happens when obj1 = obj2, which performs a shallow copy by default, just like clone in PHP. It can perform your deep copy or other custom copy by overloading the assignment copy operation, which is equivalent to the__clone() member function in PHP;
The third is memberwise initialization, which runs automatically when parameters are passed, return values are passed, or containers containing objects are initialized. You can control its effect by defining your own copy constructor.
The copy constructor is rarely used in PHP because it is passed by reference rather than a direct copy of the object.
Introduction to PHP:
PHP (PHP: Hypertext Preprocessor) is a scripting language that executes on the server side, especially for Web development and can be embedded in HTML. PHP syntax learned C language, absorbing Java and Perl features of a number of languages to develop their own characteristics of syntax, and according to their long-term continuous improvement to upgrade themselves, such as java object-oriented programming, the language was originally created to allow developers to quickly write high-quality web sites. [1-2]PHP supports both object-oriented and process-oriented development and is very flexible to use.
Introduction to C++:
C++ is the inheritance of C language, it can not only carry out procedural programming of C language, but also object-based programming characterized by abstract data types, and object-oriented programming characterized by inheritance and polymorphism. While C++ excels at object-oriented programming, it can also do process-based programming, so C++ can adapt to the size of the problem.
C++ not only has the practical characteristics of efficient computer operation, but also devotes itself to improving the programming quality of large-scale programs and the problem description ability of programming languages.
About "php and c++ what is the difference" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.