PHP Object-oriented knowledge points

Source: Internet
Author: User

Object-oriented knowledge:
1 you opposite to the object of understanding
Object-oriented (OO) appeared in the the 1970s, object-oriented is a way of understanding things, using analogy patterns.

2 What is a class? What is an object? The relationship between a class and an object?
(A class is a collection of a set of objects with the same properties and services.) It provides a unified, abstract description of all objects that belong to the class, including two main parts of properties and services.
An object is an entity used to describe an objective thing in a system, which is a basic unit of a system.
The class is abstract (appearance = = property, do things = Behavior), object (entity) is specific, object is an instantiation of the class


3 Object-oriented 3 major features
Encapsulation, inheritance, polymorphism.

4 How do I create an object of a class?
Names of class classes

5 What is a constructor method (function)? How to define? What are the characteristics?
Constructors, also known as construction methods, are methods that are called automatically when an object is created, and are used to complete class initialization.
__construct
The constructor method cannot be defined repeatedly, and there can be only one in each class, if it does not write an empty function that has a default without parameters and does not have any execution statements.

6 What is a destructor method (function)? How to define? What are the characteristics?
destructor (__destruct): Executes when an object becomes garbage or when an object is displayed for destruction. Called automatically when an object of a class is destroyed, as opposed to a constructor, which is used to destroy an object.
It will also be used for synchronous destruction of the associated data, which is automatically called, and the destructor cannot pass parameters.


7 What is encapsulation? What's the effect? List some examples of encapsulation
Information masking, encapsulation, all functions and methods, properties and behaviors in classes are also encapsulated.
It is convenient to call, avoid writing too many duplicate code.
Three access modifiers public, protected, private are also encapsulated


8 What are the 3 access modifiers? What are the roles and characteristics of each?
Three access modifiers public, protected, private
Public common people can be used, can also be modified; protected protected only by themselves and descendants can be used and modified; Private proprietary only can be used and modified;

9 What is inheritance? What is the keyword? What's the effect?
Inheritance: Extending the contents of the parent class, keyword: extends

10 What is polymorphism?
A state is the ability to redefine or change the nature and behavior of a class in object-oriented contexts based on the context in which the class is used.

11 keyword This,super What is the respective use? What's the difference?
This: invokes the properties and methods of the current object in the class.
Super: A class can invoke a constructor declared by a parent class.
One is the current object, one is the parent class


What is the function of static? How to access with static modification
Static, which can modify the property variable, or modify the function method,
Standard access mode for static resources ==> class name:: static resource name;

Usage of Parent
Parent:: Method

14 What do you mean by overloading?
A method with the same name as the parent class appears in the subclass, and this is called rewriting, and rewriting is the redefinition of the behavior

The role and usage of the final keyword
Final keyword, meaning final, final, it can modify the function method, the modified function method cannot be overridden, the properties of the class cannot be final modified, final can be modified class,
But the modified class cannot be inherited.

16 What does abstraction mean? Abstract methods and abstract classes
Abstract is not an exact description, but there is a certain concept or name, in PHP to declare an abstract class or method we need to use the Adstract keyword.

2. Abstract methods and definitions of abstract classes

At least one of the methods in a class is abstract, which we call abstract classes. So if you define an abstract class, you first define an abstract method.

Abstract class class1{

Abstract function fun1 ();
......
}

1. There is at least one abstract method in the class
2. The abstract method does not allow {}
3. Abstract methods must be added before

17 What does interface mean? What is the keyword? What are the characteristics?
Interface (interface): An interface is a collection of abstract methods and static constant definitions. An interface is a special kind of abstract class.
Implements
In the interface can only be defined by the public abstract method (no function body part), can also have static constants, interface using the plug-in configuration, can be arbitrarily matched to any class,
Classes can implement (implements) interfaces, which can have countless interfaces, and when a class implements an interface, all the methods of that interface must be implemented in that class.

18 What is the Magic method? What are they about?
Two underline (__) methods are preserved as magic methods
__construct, __destruct, __call, __callstatic,__get, __set, __isset, __unset, __sleep, __wakeup, __toString, __set_state ,
__clone, __autoload

19 How do I access and set private properties in a class?
Private Function name () {}

20 Enumerate the common magic methods and their uses? Minimum of 4
__get ($property) Access this method when an undefined property is called
__set ($property, $value) is called when an undefined property is assigned a value
__isset ($property) This method is called when the Isset () function is called on an undefined property
__unset ($property) This method is called when the unset () function is called on an undefined property

21 function and usage of namespaces
Namespaces (namespace): Namespaces are a way of encapsulating things, followed by the names of spaces;
Namespace Space Name

What is PDO?
Is the way to manipulate the database,
PDO is the function of the operation of the database encapsulated into a PDO class, in the meantime to do security verification.


23 What does a template engine mean? What is it used for?
Smarty: a php template engine written in PHP, designed to be separated from the artwork using a PHP program.

PHP Object-oriented knowledge points

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.