How does the introduction of Object-Oriented Programming in PHP 5 affect code structure and efficiency?

The introduction of Object-Oriented Programming in PHP 5 allows for better code organization, reusability, and maintainability. By using classes and objects, developers can encapsulate data and behavior, leading to more efficient and structured code.

<?php

class Person {
    public $name;
    public $age;

    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }

    public function greet() {
        echo "Hello, my name is $this->name and I am $this->age years old.";
    }
}

$person1 = new Person("John", 30);
$person1->greet();

?>