Let's practice what we have just learned
* Press on the "solution button" to see our suggested solution.
The use of static methods and variables is appropriate in the following cases:
- A Whenever we want to use a class's method without instantiation.
- B For utilities such as conversion between units of measurements, sanitation, encryption, etc.
- C When we would like to unit test our code.
- D When our code is static.
BWe might consider the use of static methods and variables when we need utility methods, with some common uses being: counters, sanitation, encryption, unit conversion, and any other methods that only give services to our program's main classes.
Scratchpad to practice your coding *This will not be saved nor submitted to us.*
//Your practice code
Was this tutorial helpful?
If so, the eBook"The essentials of object oriented PHP" can further help you.
"The essentials..." is an in-depth guide to help you quickly and easily increase your productivity and become a hot commodity in the job market.
Don't waste time!
Click on the green button to buy the eBook and start achieving your potential today!