This article mainly introduces the class modifier of PHP and access modifiers, has a certain reference value, now share to everyone, the need for friends can refer to
class modifier
1.abstract decorated class is abstract class, if a class contains abstract methods then this class is abstract class (of course, there is no abstract method in a class, we can also define this class as abstract class), then what is abstract method, abstract method is no method body method (no curly braces and the contents of the inside), The abstract method is preceded by an abstraction modifier. The abstract class itself cannot be instantiated, and only one class inherits it, overwriting all of its abstract methods so that we can instantiate its subclasses
Abstract class my{ abstract function Say ();} Abstract class my{ function Say () { echo ' hello '; }}
2.interface decorated classes are interfaces, interfaces are somewhat similar to abstract classes, but the difference is that all methods of an interface are abstract methods, and the interface's abstract method is not preceded by an abstract adornment, and the member property must be a constant. Interface references differ from class-inheriting keyword extends, where inheritance can only be singular, and interfaces may use keywords to implements multiple references and separate them with commas.
Interface Demo {Const NAME = "Constant object property"; function fun1 (); function fun2 ();//abstract method. } class MyPc extends Root implements demo, Demo2, Demo3 {...}
Access modifiers
If the access Control permission allows, you do not have to create the class object and directly use the class name plus two colons "::" Call, static properties, only one copy in memory, for all instances of the common, static methods cannot call non-static properties. You cannot use Self:: Call a non-static property.
function test () {static $a =1; $a *=2;echo $a. " \ n ";} Test () test () test ()//print result//2//4//8
The initialization of a static variable is assigned only once, and the subsequent test method is no longer initialized.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!