Method 1 for PHP object-oriented programming and development of large PHP projects

Source: Internet
Author: User
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 ;}}?> --------------------------------------------------------------------------------

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.