Learn
Now you have the knowledge to create your own classes and objects in PHP using OOP! Take some time to review the concepts before moving on:
- Classes are defined using the
class
keyword. - Functions defined within a class become methods and variables within the class are considered properties.
- There are three levels of visibility for class members:
public
(default) - accessible from outside of the classprotected
- only accessible within the class or its descendantsprivate
- only accessible within the defining class
- Members can be defined to be
static
.- Static members are accessed using the Scope Resolution Operator (
::
).
- Static members are accessed using the Scope Resolution Operator (
- Classes are instantiated into objects using the
new
keyword.- Members of an object are accessed using the Object Operator (
->
).
- Members of an object are accessed using the Object Operator (
Instructions
We’ve included some examples of using classes in PHP. Use this space to play around with the concepts and move on when you are ready.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.