One of PHP object-oriented

Source: Internet
Author: User

1. Object-oriented versus process-oriented comparisons

Process-oriented: event-centric, in several steps to complete. Not extensible, HTML does not separate from PHP

Object oriented: act as a conductor, directing others to do it. Extensible, HTML and PHP code separation

2. What is an object? object: Something that can be seen in a variety of natural forms (which is not very accurate in the code), which is performed by code in 3. What is Object-oriented? OOP (Object-oriented programming) is an acronym for OBJECT-ORIENTED programming, with flexibility, maintainability, and the ability to open a door for programmers

Three goals of software engineering: 1. Reusability 2. Flexibility 3. Scalability

Features of object-oriented programming: ① package ② inheritance ③ polymorphism

4. What is a class? Description of the abstract with properties and method objects 5. The definition of a class defines the angle: Static Description: It is the dynamic description of the variable we are familiar with (the function of the object): The dynamic description is written as a function, and the function declared in the object is called the method, and all of the classes are declared from the Properties and methods are members of a class, and properties are called member properties of an object, and methods are called member methods of an object. Member properties: A variable that is declared directly in a class. You can use scalar and composite types in PHP, so you can also be an object instantiated by other classes, and there is no point in using resources and empty types (null) in a class. The initial value of the member property is usually not assigned, and most of the time the object is instantiated and the corresponding member property is assigned an initial value. Member Method: Functions declared in an object are called methods, and the member properties and member methods described above and the declaration variables in the process are the same as functions, except for some keywords public protected private, etc.
Class classname{    //Member properties public    $name;    public $age;    Member method public    function __construct ($name, $age) {        //method body        $this->name= $name;        $this->age= $age;    }    Public Function Method () {        //method body        //return return value}  

  

6. The instantiation of a class and an object's relationship class is an object.
Instantiate $mod = new Classname ();
A "$ variable name" is a reference name that creates an object through a class, followed by this reference to access the members of the object "new" means to create a new object "class name" to represent the type of the new object "parameter" specifies the constructor of the class to initialize the value of the object if the constructor method is not defined in the class. PHP automatically creates a default constructor without parameters. A class can instantiate an object, each object independent of each other, properties and methods are not shared, (such as the same glass design, you can make thousands of glasses according to this figure, but when a glass is broken, The others are not broken), that is, they belong to a glass class. 7. Access to members of members in an object is two member property member methods for member properties There are also two operations: 1: Assignment operation 2. Getting member property values
$ reference Name new class name ([parameter list]); Object Instantiation $ Reference Name, member property = value;              Assign value to member property echo $ reference name, member property;           Gets the value of the member property of the reference name-to member method;                   Accessing member methods
If a member of an object is not static, the only form of access is the object reference name-Properties (no $ symbol), and the object reference name, method name (). 8. Special object Reference "$this"

Outside of the object we can instantiate an object and access the object's members with a reference to the object. But what happens when you want to access the members of an object inside an object? To instantiate in-house, the answer is no. Here you introduce a special object that references "$this".

The $this represents this object, and the $this, properties, and $this-based methods are accessed in member methods inside the object. You can only use 9 in member methods. Construction method and destructor Method (Magic Method) Construction method:

① If you declare a class without declaring it, the class will default to a constructor that has no argument list and the content is empty. If it is declared, the default constructor will not exist.

② when an object is instantiated, it is called automatically once, and every time an object is instantiated with the new keyword, it is called once. The constructor method cannot be invoked actively through the object's reference.

③ are typically used to assign an initial value to a member property.④PHP5 Previous versions must have the same method name and class name⑤ the same class can have only one constructor method
Public Function __construct () {    //body}
Destructor: ① allows certain actions to be performed before the small Fai GE object (close file, release result set) ② does not have any parameters when the object in the heap memory loses his access reference, it is considered a garbage object and is recycled. The destructor is called before the garbage collector reclaims the object.
Public Function __destruct () {    //method body}

  



One of PHP object-oriented

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.