I opened the PHP space yesterday, and the server is installed with the PHP4 version. I have been writing in PHP for nearly twenty days. The platform I built is PHP5. Of course, I am very careful when writing, because almost every piece of code has important points. I checked the reference first and then wrote it out. Then you can see in the reference which ones are supported by php4 and which ones are new in php5. After the results were uploaded, I realized that I had to modify them! !
1. Modify the class method call in the string. I wrote the string as follows in php5:
$htmlstr=<<< a href="user.php?u={$dataobj->getuserinfo('name')}">User Information
HTML;
Finally for PHP4 I had to change it to:
$user=$dataobj->getuserinfo('name');
$htmlstr=<<User Information
HTML;
2. Class method call returns object problem. I wrote this in php5:
$user=$dataobj-> readrecord()->d_user;
And finally in PHP4 I had to change to
$row=$dataobj->readrecord();
$user=$row->d_user;
Originally I wanted to add () and write:
$user=($dataobj->readrecord())->d_user;
Let me return the object first, and then call the attributes on the object. Then throw away the object. But it turns out that php4 does not have this support for objects! !
3. The default parameters of the function, I wrote it like this in php5:
function set($a,$b=3){
echo $b;
}
The call is set(4);
In php4, the default value of $b cannot be obtained. For reference, you can use func_num_args(), func_get_arg(), and func_get_args() functions to obtain variable length parameters.