What is the correct syntax for adding a new variable to an object in PHP?

To add a new variable to an object in PHP, you can simply use the arrow operator (->) to access the object's properties and assign a value to a new variable. This allows you to dynamically add new variables to an object without having to define them in the class beforehand. Example:

// Create an object
$person = new stdClass();

// Add a new variable to the object
$person->name = "John Doe";
$person->age = 30;
$person->city = "New York";

// Access and display the new variables
echo $person->name; // Output: John Doe
echo $person->age; // Output: 30
echo $person->city; // Output: New York