What are the advantages of using PHP5 over PHP4 for object-oriented programming?

PHP5 introduced many improvements over PHP4 for object-oriented programming, including better support for object-oriented features such as visibility (public, protected, private), abstract classes, interfaces, and exceptions. PHP5 also introduced the concept of constructors and destructors, making object initialization and cleanup more robust. Overall, PHP5 offers a more modern and powerful object-oriented programming experience compared to PHP4.

// PHP5 code snippet demonstrating the use of visibility and constructors
class MyClass {
    private $privateVar;
    
    public function __construct($value) {
        $this->privateVar = $value;
    }
    
    public function getPrivateVar() {
        return $this->privateVar;
    }
}

$obj = new MyClass("Hello");
echo $obj->getPrivateVar(); // Output: Hello