PHP OOPLesson 44Free preview
PHP Classes/Objects
This lesson is part of PHP · All levels
Summary
A class is a blueprint that defines a property as data and a method as behavior, whereas an object is a real instance made of that class. In PHP you create an object with the new keyword, then access its members using the -> sign. With OOP, code becomes more organized, reusable, and easier to maintain as the project grows.
Key points
- Class describes structure and behavior, objects are the result of an instance of a class.
- The data-storage property and the method running the action, both of which are accessed via the -> sign.
- The new keyword is used to make an object from a class.
- $this refers to an object running so that the method can access its own properties.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.