Why are static methods and attributes used? It has several features that are useful: you can access static methods and attributes without instantiating classes, and can use them anywhere in the code! & Amp; lt ;? Phpheader (& quot; Content-type: text/htm
Why are static methods and attributes used? It has several features that are useful: you can access static methods and attributes without instantiating classes, and can use them anywhere in the code!
Note that:
1. static methods cannot access common attributes, but can only access static attributes.
2. the static method uses the class as the scope, so you can use: to connect static attributes and static methods without instantiation.
3. pseudo keywords cannot be used in static methods.
So what are the differences between constant and static attributes?
A constant attribute is named after an uppercase letter instead of starting with $. The difference between a constant attribute and a static attribute is that it cannot be re-copied. Otherwise, an error will be parsed.