[Object-OrientedBootcamp] 7-Statics-and-Constants you may see some articles on the Internet, which mention static is harmful. What do they mean? Is this true? Okay. let's talk about this in this section.
Learn through examples
Before the transformation, the dynamic call is as follows:
Add (1, 2, 3); // result int (6)
After the original dynamic transformation, the static call is as follows:
After being transformed to a static method, you can directly call it using the class name.
Another exampleStatic variable usage:
HaveBirthday (); $ joe-> haveBirthday (); $ jane = new Person (); $ jane-> haveBirthday (); echoPerson: $ age; // not 2, the result is 4. The $ age variable is static and shared.
Const identifier:
Use in LaravelIn Illuminate \ Support, the Str class uses a large number of static variables and static methods, for example:
EchoStr: lower ("FOOBAR"); // Result: foobarechoStr: camel ();
Reference link:
* PHP5: const vs static