How can developers ensure their code is compatible with both PHP 4 and PHP 5 when using classes?
Developers can ensure their code is compatible with both PHP 4 and PHP 5 when using classes by avoiding the use of PHP 5-specific features such as visibility keywords (public, private, protected) and magic methods (__construct, __destruct, __get, __set). Instead, they can use PHP 4-compatible syntax by declaring all class members as public and using constructor methods with the same name as the class.
class MyClass {
var $property;
function MyClass() {
// Constructor code
}
function method() {
// Method code
}
}