Properties and Methods
Last updated
What is Properties and Methods?
Properties and Methods are fundamental components of Object-Oriented Programming (OOP) in PHP. Properties are just like variables; they hold information that an object will need to use. Methods, on the other hand, are similar to functions; they perform an action on an object's properties. In PHP, properties are declared using visibility keywords (public, protected, or private) followed by a regular variable declaration, while methods are declared like functions but inside a class.
Here is a simple example:
class Car {
public $color; // Property
// Method
public function setColor($color) {
$this->color = $color;
}
}
In this example, $color is a property and setColor() is a method.
Free resources to learn Properties and Methods
- Official docsProperties and Methods
More in stage 11: OOP Fundamentals
- OOP Fundamentals
- Classes and Objects
- Constructor / Destructor
- Access Specifiers
- Static Methods and Properties
- Inheritance
- Input Validation
- SQL Injection
- XSS Prevention
- CSRF Protection
- Password Hashing
- Auth Mechanisms
- Sanitization Techniques
- PDO
- MySQLi
- Object-Relational Mapping (ORM)
- Database Transactions
- Connection Pooling
- Performance Optimization
- Database Migrations
Properties and Methods: common questions
Can I learn Properties and Methods in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Properties and Methods in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Properties and Methods tutorial for beginners?
It is lesson 63 of 120 in the free PHP roadmap, in stage 11, OOP Fundamentals. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.