PHP object-oriented foundation problems

1. What is object-oriented (understanding the answer)?
Is "Everything Is an Object", all things popular explanation; object oriented OO = Object-Oriented Analysis OOA + object-oriented design OOD + object-oriented programming OOP: A are treated as separate object may be one (unit), they can complete their own function, rather than as functions into a C.

Now pure OO language is mainly Java and C #, PHP, C ++ supports OO, C is process-oriented.

2, brief private, protected, public access modifier.
Answer: private: private members can be accessed from within the class.

protected: the protection of members of the class inside and inheritance classes can be accessed.

public: public members, full disclosure, no access restrictions.

3, the difference between stack and heap?
A: The stack is allocated during compilation good memory, so your code on the stack size must have clearly defined;

The heap is dynamically allocated memory during program execution, you can determine the size of the heap memory to be allocated in accordance with the operation of the program.

4, the main difference between XML and HTML
Answer: (1) XML is case-sensitive letters, HTML is not case.
(2) in HTML, if the context clearly show paragraph or list of keys at the end where you can omit
or
end tag or the like. In XML, it must not be omitted end tag.
Element end tag (3) in XML, we have a single tag must be without a matching / character as the end. So the parser knows not find the end tag.
(4) In XML, attribute values must be dispensed in quotes. In HTML, quotation marks may or may not.
(5) In HTML, you can have the attribute name without value. In XML, all attributes must have a corresponding value.

5, object-oriented features have what?
A: There are encapsulation, inheritance, polymorphism. If you add four aspects: abstract.
To understand the following explanation:
Package:
packaging is to ensure excellent basic software components of the module, the package goal is high cohesion, to achieve low coupling software components, programs to prevent the impact of changes brought interdependence.
Inheritance :
in the definition and implementation of a class, can be carried out up the basis of an existing class, the contents of this existing class defined as its content, and can add a number of new content, or modify the original methods to make it more suitable for specific needs, which is inherited. Inheritance is a mechanism parent class data and methods of subclasses automatic sharing, this is a relationship between classes, to improve the reusability and extensibility of the software.
Polymorphism:
polymorphism refers to the particular type of reference variables defined in the program is directed and emitted by this method is called when programming reference variable is not determined, but is determined only during the program run, i.e. it is going to be a reference variable which points to an object instance of the class, this reference variable method calls made in the end is which class method implemented, in order to be determined by the program is running.
Abstract:
Abstract is to find some similarities and common place things, and these things will be classified as a class that only consider the similarities and common place these things, and ignores those aspects not related to current themes and objectives, focus on aspects related to the current target. For example, see an ant and an elephant, you can imagine their similarities, it is abstract.

6, the concept of abstract classes and interfaces, and the difference?
A: The abstract class: which is a special and can not be instantiated, used only as a parent of other classes. Use the keyword abstract statement.
It is a special kind of abstract class is a special class, using the interface declaration.
Operation (1) abstract class keyword extends implemented through inheritance, and using the interface is achieved through the implements keyword.
(2) there is an abstract class data members, the package data can be achieved, but that no data members.
It can be configured to process (3) abstract class, but the interface does not constructor.
(4) abstract class method by private, protected, public key modification (abstract method is not private), and interface methods use the public key can only be modified.
(5) in a class can inherit an abstract class, and a class can implement multiple interfaces simultaneously.
(6) There can abstract class code that implements a method, which may not have the code that implements the interface member methods.

7. What is the constructor, destructor what is, what is the effect?
A: constructor (method) is the first object is created after completion method is automatically invoked object. It exists in every class declaration, it is a member of a special method. Role is to perform some initialization tasks. Php using the __construct () constructor statement, and only a declaration.
Destructor (Method) constructor function and on the contrary, is a method called automatically last object before the object is destroyed. PHP5 is the role of newly added content is used to achieve the implementation of certain operations before destroying an object, such as closing files and releasing memory.

8, the method of how to reload the parent class, illustration
A: overloaded, i.e. covering the parent class, which is an alternative method in the subclass inherits from the parent class method, also called the overwrite method.
Covering the parent key is to create a method in the subclass in the same manner as the parent class includes method name, return type and argument. The same can name only requires PHP methods.

9, a method commonly used magic What? Illustrate
Answer: php provisions with two underscores (__) at the beginning of the method are as magical method, it is recommended that you better not __ function names begin with, unless it is to overload the existing methods of magic.
the __construct () is automatically called when the class is instantiated.
__destruct () class object is automatically called when the end use.
__set () call to an undefined time in the properties of assignment.
__get () call to an undefined property when called.
__isset () using isset () or empty () function will be called when.
__unset () using unset () will call time.
__sleep () using serialize serialization when calling.
__wakeup () using unserialize deserialization when called.
__call () method call that does not exist when called.
static method __callStatic () call is a call that does not exist.
__toString () to convert an object into a string of time will be called. Such as echo.
__invoke () call when attempting to put the object when the method is called.
__set_state () when using var_export () function when called. Accepts an array parameter.
__clone () when using a clone copy an object when you call.

10, $ this and self, parent these three words are representative of what? Used in what situation?
Answer: $ this current object
self current class
parent of the current super class
$ this in the current class, use the -> call the properties and methods.
self current class is also used, but need to use :: call.
in parent class.

11, how the constants defined in the class, the class how to call constant, how to call constants outside the class.
A: The class constant that is a member of the constant, constant is the amount does not change, is a constant value.
Keyword defines constants const.
For example: const PI = 3.1415326;
outer whether the class or classes, constants and variables to access is not the same, the constant need to instantiate objects,
to access constants format class names are scoped switch symbols (double colon) to call.
Namely: Class name :: Class constant name;

12, the scope operator :: How to use? They are used in which situations?
A: call the class constant
static method call

13, works __ autoload () method is what is?
A: The basic conditions for the use of the magic of this function is the file name of the file to the class and the class name consistent.
When the program is executed to instantiate a class, if not before the introduction of the class file instantiated, then automatically performs __autoload () function.
According to this function to find the name of the instance of the class of the class file path, after determining the existence of this class file class file path
on the implementation of the class include or require to load, then the program continues, if this path on an error when this file does not exist.
Use magic function can automatically load necessary to write a number of include or require functions.


---------------------
Original: https: //blog.csdn.net/mo3408/article/details/80751965

Guess you like

Origin www.cnblogs.com/gjh99/p/11277621.html