Method 3 for developing large PHP projects

Source: Internet
Author: User
Overload (different from overwriting) is not supported in PHP. In OOP, you can overload a method to implement two or more methods with the same name, but there are different numbers or types of parameters (depending on the language ). PHP is a loose language, so it does not work through type overloading. However, the parameter SyntaxHighlighter. all ();

Overload (different from overwriting) is not supported in PHP. In OOP, you can overload a method to implement two or more methods with the same name, but there are different numbers or types of parameters (depending on the language ). PHP is a loose language, so the type overload does not work, but the overload does not work by the number of parameters. Sometimes the overload constructor in OOP is very good, so that you can create objects using different methods (passing different numbers of parameters ). Tips for implementing it in PHP :----------------------------------------------------- $ Name (); // note that $ this-> name () is generally incorrect, but here $ name is the name of the method to be called} function Myclass1 ($ x) {code;} function Myclass2 ($ x, $ y) {code ;}}?> ----------------------------------------------- The class is transparent to users through additional processing in the class: $ obj1 = new Myclass (1 ); // call Myclass1 $ obj2 = new Myclass (1, 2); // call Myclass2, which is sometimes very useful. Polymorphism is a kind of object capability. it can decide which object method to call at runtime based on the passed object parameters. For example, if you have a figure class, it defines a draw method. The circle and rectangle classes are derived. in the derived class, you override the draw method. you may also have a function that wants to use a parameter x, you can call $ x-> draw (). If you have polymorphism, the draw method that you call depends on the object type that you pass to this function. Polymorphism is in an interpreted language like PHP (imagine which method should you call when a C ++ compiler generates such code? You don't know what type of objects you have. well, this is not the point.) it is very easy and natural. Therefore, PHP certainly supports polymorphism. ----------------------------------------------------- Draw () ;}$ obj = new Circle (3,187); $ obj2 = new Rectangle (); $ board-> niceDrawing ($ obj ); // call the draw method of Circle $ board-> niceDrawing ($ obj2); // call the draw method of Rectangle?> ------------------------------------------------- Using PHP for object-oriented programming some "purists" may say that PHP is not a real object-oriented language. PHP is a hybrid language. you can use OOP or traditional procedural programming. However, for large projects, you may want/need to use pure OOP to declare classes in PHP, and only use objects and classes in your project. As the project grows, it may be helpful to use OOP, and the OOP code is easy to maintain, easy to understand and reuse. These are the basis of software engineering. Applying these concepts in web-based projects will become the key to future website success.

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.