1. What is object-oriented?
Object-Oriented Oo = object-oriented analysis Ooa + object-oriented design Ood + Object-oriented programming oop; The popular explanation is that "all things are objects", and all things are considered to be independent objects (units), they can do their own functions, rather than as a C as a function.
2, briefly describe the private, protected, public modifier access rights?
- Private: A privately owned member that can be accessed within a class.
- Protected: A protected member that can be accessed within the class and in the inheriting class.
- Public: Common members, completely public, without access restrictions.
3. What is the difference between heap and stack?
- Stacks are allocated memory space during compilation, so your code must have a clear definition of the size of the stack;
- A heap is a dynamically allocated memory space during a program's run, and you can determine the size of the heap memory to allocate depending on how the program is running.
4. What is the main difference between XML and HTML?
(1) XML is case-sensitive, HTML is not distinguished.
(2) in HTML, if the context clearly shows where the paragraph or list key ends, you can omit or sort the end tag. In XML, you must never omit the end tag.
(3) in XML, an element that has a single tag without a matching closing tag must end with A/character. This way the parser knows not to look for the end tag.
(4) in XML, attribute values must be enclosed in quotation marks. In HTML, the quotation marks are available for use.
(5) In HTML, you can have a property name without a value. In XML, all attributes must have corresponding values.
5. What are the aspects of object-oriented features?
- There are mainly encapsulation, inheritance, polymorphism. In the case of 4, add: abstract.
- The following explanations are for understanding:
- Packaging:
- Encapsulation is to ensure that the software components have excellent modularity, the goal of the package is to achieve high cohesion of software components, low coupling, to prevent program interdependence and the impact of the changes.
- Inherited:
- When defining and implementing a class, it can be done on the basis of an already existing class, with the content defined by the existing class as its own content, and by adding some new content, or modifying the original method to make it more suitable for a particular need, which is inheritance. Inheritance is the mechanism by which subclasses automatically share the parent data and methods, which is a relationship between classes, which improves the reusability and extensibility of the software.
- Polymorphic:
- Polymorphism refers to the specific type of reference variable defined in the program and the method call emitted by the reference variable is not determined during programming, but is determined during the program's run, that is, a reference to which the variable is inverted to the instance object of the class that the reference variable emits, and the method called by which class is implemented. Must be determined by the time the program is running.
- Abstract:
- Abstraction is the identification of similarities and commonalities of things, and then the attribution of these things to a class that considers only the similarities and commonalities of these things, and ignores those aspects that are irrelevant to the current subject and goal, focusing on aspects related to the current goal. For example, when you see an Ant and an elephant, you can imagine the similarities between them, which is abstraction.
6. What are the concepts and differences between abstract classes and interfaces?
Abstract class: It is a special class that cannot be instantiated and can only be used as a parent class of other classes. Use the abstract keyword declaration.
It is a special kind of abstract class, also a special class, using the interface declaration.
(1) The operation of the abstract class is implemented by inheriting the keyword extends, while the use of the interface is implemented by the Implements keyword.
(2) There are data members in the abstract class, which can implement the encapsulation of the data, but the interface has no data members.
(3) An abstract class can have a construction method, but the interface does not have a constructor method.
(4) The methods of an abstract class can be modified by the private, protected, public keywords (abstract methods cannot be private), whereas methods in an interface can only be decorated with the public keyword.
(5) A class can inherit only one abstract class, and a class may implement multiple interfaces at the same time.
(6) An abstract class can have the implementation code of the member method, and the interface can not have the implementation code of the member method.
7, what is a constructor, what is a destructor, what is the function?
- A constructor (method) is the first method that is automatically called by an object after the object is created. It exists in each declared class and is a special member method. The role is to perform some initialization tasks. PHP uses __construct () to declare construction methods, and only one can be declared.
- The destructor (method) acts on the opposite side of the construction method, which is the last method that is automatically called by the object before the object is destroyed. The new content added in PHP5 is used to implement certain actions, such as closing files and freeing memory, before destroying an object.
8, how to overload the parent class method?
- Overloading, the method that overrides the parent class, that is, by using a method in a subclass to replace a method inherited from a parent class, also called a method override.
- The key to overriding the parent class method is that the same method that is created in the child class in the parent class includes the name of the method, the parameter, and the return value type. PHP requires only the same name of the method.
9. What are the common magic methods?
PHP rules to start with two underscore (__) methods are preserved as a magic method, it is recommended that the function name is best not to start without __, unless it is to reload the existing magic method.
- __construct () is called automatically when the class is instantiated.
- The __destruct () class object is automatically invoked at the end of the use.
- __set () is called when a value is assigned to an undefined property.
- __get () is called when undefined attributes are called.
- __isset () is called when the isset () or empty () function is used.
- __unset () is called when the unset () is used.
- __sleep () is called when serialized using Serialize.
- __wakeup () is called when deserialization is used with unserialize.
- Called when __call () calls a nonexistent method.
- __callstatic () calls a non-existent static method that is called.
- __tostring () is called when the object is converted to a string. Like Echo.
- __invoke () is called when an attempt is made to invoke an object as a method call.
- __set_state () is called when the Var_export () function is used. accepts an array parameter.
- __clone () is called when copying an object using clone.
10. What do the three keywords, $this and self, and parent represent respectively?
- $this Current Object
- Self Current class
- Parent of the current class
- $this used in the current class, call properties and methods using.
- Self is also used in the current class, but needs to use:: Call.
- The parent is used in the class.
11. How to define constants in a class, how to call constants in a class, and how to call constants outside of a class.
- The constant in the class is the member constant, which is the amount that does not change, and is a constant value.
- Defines constants using the keyword Const.
- For example: const PI = 3.1415326;
- Constant access and variables are not the same, whether inside or outside the class, and constants do not need to instantiate the object.
- The format of the access constant is called by the class name plus the scope operation symbol (double colon).
- That is: Class Name:: Class constant name;
12. How does the __autoload () method work?
- The basic condition for using this magic function is that the file name of the class is consistent with the name of the class.
- When a program executes to instantiate a class, the __autoload () function is automatically executed if the class file is not introduced before instantiation.
- This function will find the path to the class file based on the name of the instantiated class, and when it is determined that the class file exists under this class file path
- Executes an include or require to load the class, and then the program continues execution, prompting an error if the file does not exist under this path.
- Using the auto-loaded magic function eliminates the need to write many include or require functions.
PHP Advanced Knowledge