Home > Backend Development > PHP Tutorial > PHP object-oriented programming method to develop large-scale PHP projects reprinted_PHP tutorial

PHP object-oriented programming method to develop large-scale PHP projects reprinted_PHP tutorial

WBOY
Release: 2016-07-13 17:23:10
Original
985 people have browsed it

Object-oriented programming in PHP: Methods for developing large-scale PHP projects (1) Author: Luis Argerich Translator: limodou This article introduces object-oriented programming (OOP, Object Oriented Programming) in PHP. I'll show you how to reduce coding and improve quality by using some OOP concepts and PHP tricks. Good luck! The concept of object-oriented programming: Different authors may have different opinions, but an OOP language must have the following aspects: Abstract data types and information encapsulation, inheritance, and polymorphism are encapsulated through classes in PHP: ---- -------------------------------------------------- --------------------------x=$v; } function getX() { return $this->x; } } ? >------------------------------------------------ ---------------------------------- Of course you can define it according to your own preferences, but it is best to maintain a standard, so will be more effective. Data members are defined in the class using the "var" declaration. Before the data members are assigned a value, they have no type. A data member can be an integer, an array, an associative array, or an object. Methods are defined as functions in the class. When accessing class member variables in the method, you should use $this->name. Otherwise, for a method, it can only be a local variable. Use the new operator to create an object: $obj=new Something; You can then use member functions via: $obj->setX(5); $see=$obj->getX(); In this example, the setX member The function assigns 5 to the object's member variable x (not the class), and then getX returns its value 5. You can access data members through class references like: $obj->x=6. This is not a good OOP habit. I strongly recommend accessing member variables through methods. You will be a good OOP programmer if you treat member variables as unmanipulable and use methods only through object handles. Unfortunately, PHP does not support declaring private member variables, so bad code is allowed in PHP. Inheritance is easy to implement in PHP, just use the extend keyword. -------------------------------------------------- ------------------------------- y=$v; } function getY() { return $this->y ; } } ?>------------------------------------------------ ---------------------------------- Reprinted from PHPBuilder.com

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532248.htmlTechArticleObject-oriented programming in PHP: Methods for developing large-scale PHP projects (1) Author: Luis Argerich Translator: limodou This This article introduces object-oriented programming (OOP, Object Oriented Pro...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template