In PHP5.0 and above, it is also compatible with the constructor definition rules of version 4.0. If both the 4.0 constructor and the __construct() function are defined, the __construct() function takes precedence.
In order to make the class code compatible with PHP 4.0 and 5.0 at the same time, you can take the following method:
Copy the code The code is as follows:
class MyClass {
function __construct() { //for PHP5.0
echo 'this is class2 construct';
}
// In order to make the class The code is compatible with both PHP4.0 and 5.0
function MyClass() { //for PHP4.0
$this->__construct();
}
}
$c3 = new MyClass ;
?>
http://www.bkjia.com/PHPjc/328098.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328098.htmlTechArticleIn PHP5.0 and above, it is also compatible with the constructor definition rules of version 4.0. If both the 4.0 constructor and the __construct() function are defined, the __construct() function takes precedence. ...