1, the function name, with _ or a-z or A-Z to start; 2, a custom function in the variable is local, the function does not take effect outside; 3, when using global variables, you can use variables outside the function; 4. To prevent variable conflicts during the function call, you can use unset (variable name ), be redefined later; 5, PHP
1, the function name, with _ or a-z or A-Z to start; 2, a custom function in the variable is local, the function does not take effect outside; 3, when using global variables, you can use variables outside the function; 4. To prevent variable conflicts during the function call, you can use unset (variable name ), be redefined later; 5, PHP
1, the function name, with _ or a-z or A-Z to start;
2. variables in a custom function are local and do not take effect outside the function;
3. global variables can be used outside the function;
4. To prevent variable conflicts during function calling, you can use unset (variable name) and redefine it later;
5. PHP uses value transfer by default. If reference (Address) is required, use the & variable name, such:
// Case
$ A = 213;
Functionabc (& $ B ){
$ B = 314;
}
Abc ($ );
Echo $;
6. The default value of the function;
7, '', output as is," "to be converted;
8. If you pass the basic data type (integer, decimal, Boolean, character) to the function, it is the passed value by default. If you want to transfer the address, functiontest (& $ variable ...) {...}; In php, if an array is passed to a function, the value is passed by default (a new array is copied). if the address is to be transferred, the array name should be & $
9. Basic usage of static variables:
(1) define static variables in the class; [access modifier] static $ variable name;
(2) If there are two access methods in the class: self ::$ static variable name, class name: $ static variable name
For out-of-class access, there is a method class name: static variable name;
10. php provides three access control symbols
(1). public indicates global. It can be used in this class, outside the class, and subclass.
(2) protected indicates that it is protected and can be used in this class and subclass;
(3) private indicates private and can only be used in this class.
Note: If a method does not have an access modifier, the default value is public. attribute, the access modifier must be specified. methods can be called each other, but the form is $ this reference.
Functiontest1 (){
$ This-> test2 ();
}
Protectedfunction test2 (){
Echo "hello, I'm test2 ";
}
11. inheritance is a subclass that is inherited by the attributes of the extends parent class (public, protected) and (public, protected. The basic syntax is class name extends parent class name {....};
12. A class can only inherit one parent class (direct inheritance). If you want to inherit attributes and methods of multiple classes, use multi-level inheritance. If we want to call the constructor of the parent class or other methods (public and protected), we can handle the following: ① Class Name: Method Name () ② parent :: method Name ();
13. override (override) when a parent class knows that all subclasses have a method, but the parent class is not sure how to write the method, this method can be overwritten by sub-classes. ① To implement rewriting, the method name of the subclass and the number of parameter lists must be the same as that of the parent class, but the parameter name is not required to be the same. ②, if the subclass needs to call a method (public, protected) of the parent class, you can use parent: Method Name (parameter) or parent class name: Method Name (parameter ). ③ When implementing method override, the access modifier can be different, but must meet the following requirements: the access range of the subclass> = the access range of the parent class.
14. Notes for using abstract classes (1). abstract class name {....} (2) If a class/method is modified using abstract, the class is an abstract class/abstract method. [the abstract method cannot have a method body] (3 ), abstract classes can have no abstract methods ., there are also implementation methods. (4) If an abstract method exists in A class, the class must be declared as an abstract class (5) if Class A inherits the abstract class B, class A is required to implement all abstract classes inherited from Class B.
15. Basic interface syntax
Interface name {// constant // method}
Methods In the interface cannot have a method body; implementation format: class name implements interface name {}; when multiple classes are in a hierarchical relationship, they must implement a function, but the implementation method is different. In this case, you can use the interface.
Note: (1) one interface can inherit multiple other interfaces; (2) When a class implements some interfaces, all interface methods must be implemented.
Comparison of inheritance and implementation Interfaces
(1) it can be considered that implementing interfaces is a supplement to a single inheritance; (2) a function can be extended without damaging the class hierarchy.
16,Not added before a constant$ Symbol, which is generally capitalized and assigned a value when the class or interface is declared;
17. final keyword, (1) if we want a class to be inherited by other classes, we can use final; 2. If we want a method, we cannot rewrite the subclass, you can use final to modify the method. (Final keywords cannot be used to modify attributes)
Class 18 modifiers only include final and abstract keywords. public, protected, and private (3 P) can modify member variables and member methods in the class.