Chapter One core concepts of object-oriented thinking

Source: Internet
Author: User
Tags php error print object

1. Object-oriented core thinking

The object is used as the basic unit of the program, which encapsulates the program and data to improve the reusability, flexibility and extensibility of the software.

The core idea of object-oriented is object, encapsulation, reusability and extensibility.

2. Application of Magic Method

__set () To set properties that cannot be accessed externally

__get () Get externally inaccessible properties

This method is called when __call () calls a method that does not exist

__callstatic () calls this method when it calls a static method that does not exist

__tostring () Print Object properties

3. Inheritance, combination and polymorphism

Combination of classes: Instantiate other classes as their own properties in a class method, more for top-level design and business logic

Class Inheritance: Single inheritance, subclass inherits all properties and methods of the parent class, more for the underlying design

Polymorphic: Same type, different results, can be implemented using interface interface type, more for core structure and core business logic

4. Interface-Oriented programming

Interface: The interface is abstract, the interface itself does not provide implementation, but provides a specification

5. Reflection API

Reflection refers to the function of dynamically obtaining information or obtaining the method of invoking object dynamically in PHP running state, which is mainly used for debugging and obtaining information of class, and also can be implemented by token function.

6. Exception and error handling

try{throw new Exception ();} catch (Exception $e) {$e->getmessage ();}

PHP can only be captured after manually throwing exceptions

PHP error is the case that causes the script to run abnormally, the error level is roughly categorized: deprecated lowest level error, such as expiration function use, notice level error, syntax error, warning error, such as function parameter mismatch; Fetal error high-level errors, can directly cause PHP script to not run; Prase error highest level errors, parsing errors. All errors can be masked using error_reporting (0), which can be used for formal deployment.

Use the Set_error_handle () error handling mechanism to customize the error function

  

  

Chapter One core concepts of object-oriented thinking

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.