8 Questions
What is the main concept of OOP in programming?
To consider everything as an object with its own properties and behaviors
What is the purpose of a class in OOP?
To hold the properties and behaviors of an object
What is an object in OOP?
An instance or occurrence of a class
What happens when an individual object is created from a class?
It inherits all the properties and behaviors from the class, but each object will have different values for the properties
How do you define a PHP class?
Using the class keyword followed by the name of the class and a pair of curly braces
What are the three visibility modifiers in PHP?
public, private, protected
How do you add properties to a class in PHP?
By placing variables inside the class
What is the correct syntax for defining a method in a PHP class?
Using the function keyword before the name of the function
Study Notes
OOP Concepts
- OOP considers everything in the world as an object, which is an entity that holds its own properties (data) via variables and behaviors (functions) via methods.
Classes & Objects
- A class is the blueprint/template that is used to hold objects along with their behavior and properties.
- An object is simply an instance/occurrence of the class.
- A class can have properties like make, color, year, speed limit, etc.
- Objects inherit all the properties and behaviors from the class, but each object will have different values for the properties.
Defining a PHP Class
- A class is defined by using the
class
keyword, followed by the name of the class and a pair of curly braces ({}
). - The class name should start with a letter, cannot be a PHP reserved word, and cannot contain spaces.
- All properties and methods go inside the curly braces.
Adding Properties & Methods to a Class
- Properties are added to the class by placing variables inside it.
- Methods are defined using the
function
keyword before the name of the function. - Properties and methods can have one of the three visibility modifiers:
public
,private
, andprotected
. - If a method is defined without any visibility modifier, it defaults to
public
.
Calling Member Functions
- After creating an object, you can use it to call the member functions or assign values to the data members (property) of that class.
- To access a property, you use the object operator (
->
). - To call a method, you also use the object operator (
->
).
Learn about Object-Oriented Programming concepts, including classes, objects, and more in the context of PHP and Advanced Web Technologies.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free