PHP OOPLesson 53Free preview
PHP Static Methods
This lesson is part of PHP · All levels
Summary
A static method is a method that is called directly by the class name using the symbol:: without the need to create an object. This method doesn't have $this because it's not tied to a particular instance. Static methods are suitable for utility functions such as validation, calculation, or object-builder.
Key points
- Static calling uses the NameClass::.
- Static method can't use $this because it runs without an object.
- Static method calls another static method with self:: or static::.
- The non-static method must be called through an object that has already been created with new.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.