What is the significance of the __construct function in PHP classes and how does it differ between PHP4 and PHP5?

The __construct function in PHP classes is used to initialize an object when it is created. In PHP4, the constructor function was named the same as the class name, while in PHP5, the constructor function is named __construct. This change was made to make the code more consistent and easier to understand.

// PHP4 constructor
class MyClass {
    function MyClass() {
        // constructor code
    }
}

// PHP5 constructor
class MyClass {
    function __construct() {
        // constructor code
    }
}