class Person { public $name; } $person = new Person(); $person->name = "John Doe"; echo $person->name; // Output: John Doe
class BankAccount { private $balance; public function deposit($amount) { $this->balance += $amount; } public function getBalance() { return $this->balance; } } $account = new BankAccount(); $account->deposit(100); echo $account->getBalance(); // Output: 100In this example, we create a class BankAccount with a private attribute $balance. We then create two public methods, deposit and getBalance, to access and manipulate the $balance attribute. We create a new instance of the class, deposit $100 and print the balance. Package/library: These examples are part of the PHP core language and do not require any external package or library.