PHP versions 4.0 and 5.0 differ greatly in class support. CompileCodeWe strongly recommend that you do not mix the 4.0 and 5.0 syntaxes.
However, in some cases, you may need to consider the compatibility of the two-generation version. The following code can be run simultaneously in PHP 4.0 and 5.0, with the same results, taking into account two versions.
Principle: php5.0 is backward compatible with the syntax of the 4.0 class. If _ construct () and Class Name functions appear at the same time, _ construct () is executed first. However, in php4.0, the _ construct () function is treated as a normal function and ignored.
Therefore, if the following code is executed in the php5.0 environment, the _ construct () function is executed first and the class3 () function is ignored.
If it is executed in the php4.0 environment, the class3 () function is executed first and the _ construct () function is ignored. However, the class3 () function explicitly calls _ construct () function.
Therefore, in both versions, the _ construct () function is automatically executed to implement the constructor.
If the following code uses a 4.0 unrecognized syntax, such as parent and self, it cannot achieve Upward compatibility.
<? PHP
// Enable the error message
Error_reporting (e_all | e_strict );
Class class3
{
Function _ construct () // For php5.0
{
Echo 'this is class3 construct ';
}
Function class3 () // For php4.0
{
$ This->__ construct ();
}
}
$ C3 = new class3;
?>
Author: Zhang Qing (mesh) 2010-4-1
From mesh horizon: http://blog.why100000.com
Why 100,000 computer learning networks: http://www.why100000.com
next article: lamp development essentials (2): WordPress plug-in mechanism analysis