PHP object-oriented programming: method for developing large PHP projects (I) Author: LuisArgerich translator: limodou This article introduces object-oriented programming (OOP, ObjectOrientedProgramming) in PHP ). I will show you how to reduce Synta by using some OOP concepts and PHP skills
PHP object-oriented Programming: method for developing large PHP projects (I) Author: Luis Argerich translator: limodou This article introduces object-oriented Programming (OOP, Object Oriented Programming) in PHP ). I will show you how to reduce coding and improve quality by using some OOP concepts and PHP skills. Good luck! The concept of object-oriented programming: different authors may have different ideas, but an OOP language must have the following aspects: abstract data types and information encapsulation inheritance polymorphism are encapsulated through classes in PHP :-------------------------------------------------------------------------------- X = $ v;} function getX () {return $ this-> x ;}}?> -------------------------------------------------------------------------------- Of course you can define according to your preferences, but it is better to maintain a standard to make it more effective. Data members are defined using the "var" declaration in the class. they have no type before assigning values to data members. A data member can be an integer, an array, an associated array, or an object. A method is defined as a function in a class. when using a member variable of the class in a method, you should use $ this-> name. Otherwise, a method can only be a local variable. Use the new operator to create an object: $ obj = new Something; then you can use the member function through: $ obj-> setX (5 ); $ see = $ obj-> getX (); in this example, the setX member function assigns 5 to the member variable x (not a class) of the object ), then getX returns its value 5. You can access data members by referencing classes like $ obj-> x = 6. this is not a good OOP habit. I strongly recommend that you use methods to access member variables. If you think of member variables as unmanageable and use methods only through object handles, you will be a good OOP programmer. Unfortunately, PHP does not support declaring private member variables, so bad code is also allowed in PHP. Inheritance is easy to implement in PHP, as long as the extend keyword is used. -------------------------------------------------------------------------------- Y = $ v;} function getY () {return $ this-> y ;}}?> --------------------------------------------------------------------------------