Instantiating Objects
- To use a class, instantiate objects from it using the
new
keyword followed by the class name and optional constructor arguments. - Objects are instances of a class and hold their own set of properties and methods.
$person1 = new Person("John", 30);
$person2 = new Person("Alice", 25);
How to Define a Class in PHP?
To declare a class in PHP, we use the keyword class followed by the class name. Class names should follow the CamelCase convention and start with an uppercase letter.