What are the key differences between OOP in PHP5 and earlier versions?

In PHP5, the key differences in OOP compared to earlier versions include the introduction of new features such as visibility keywords (public, protected, private), abstract classes, interfaces, and the ability to use constructors and destructors. These additions allow for better organization, encapsulation, and reusability of code in object-oriented programming.

<?php

// Example of class with visibility keywords in PHP5
class MyClass {
    public $publicVar;
    protected $protectedVar;
    private $privateVar;

    // Constructor
    public function __construct($publicVar, $protectedVar, $privateVar) {
        $this->publicVar = $publicVar;
        $this->protectedVar = $protectedVar;
        $this->privateVar = $privateVar;
    }

    // Method with visibility keywords
    public function getPrivateVar() {
        return $this->privateVar;
    }
}

?>