Home  >  Article  >  Backend Development  >  Good PHP learning: you will shuttle between php4 and php5 with a little insight_PHP tutorial

Good PHP learning: you will shuttle between php4 and php5 with a little insight_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:55:10828browse

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318332.htmlTechArticleI opened the php space yesterday. The server is installed with the php4 version. I started writing things in php for nearly 20 days. , the platforms I built are all php5, of course I am very careful when writing, because...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn