PHP Object Properties: Complete Guide

In PHP, you can add properties to an object directly by assigning them. For example:

class Person {
    public $name;
    public $age;
}

$person = new Person();
$person->name = "John";
$person->age = 30;

In the example above, we created a class named Person and then instantiated an object named $person. We can then add properties to the object and assign values to these properties using the arrow operator (->).

bannerAds