Home >Backend Development >PHP Tutorial >Summary of the differences between php4 and php5 (configuration similarities and differences)_PHP tutorial

Summary of the differences between php4 and php5 (configuration similarities and differences)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:22:45991browse

php4 does not have static members

Such an error occurred in the php web background. I checked SubPages1.php and did not find the corresponding error. The website is completely normal when tested locally, but after being uploaded to the space, such an error occurs. I can't even see the verification code. Similar errors include Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /www/users/myhuashun.com.ufhost/admin/yanzhengma.php on line 6

If the server is version 4.0, if there is "public", remove "public". There will be no error. If "public" is a defined variable, change "public" to "var".

Recently I am working on a whole-site content management system (see the homepage of this site), and I am also working on a friend’s office building information management system! To be honest, I have only been developing in PHP for a little over half a year, so I have very little experience. However, I have been working in WEB for several years. When I first came into contact with PHP, it was still PHP3. PHP3 did not support sessions and did not have the concept of object-oriented objects. It only had a lot of functions! At first, I was wandering among many web scripts, asp, php, and jsp were already three pillars. Of course, perl and cgi were too luxurious for students who were still beginners at that time. In fact, I also liked a lot of functions at that time, just like learning DOS commands at that time, but compared to ASP, php3 has no session and no object-oriented objects, and many small companies are using ASP, so they did not choose php at first. The reason is that the biggest progress of php4 is the addition of the idea of ​​object-oriented and the addition of session management between the server and the client. At present, most domestic hosting providers are still stuck on the php4 version, but php5 can be said to be a truly decent language!

So, when I return to PHP, I use php5 for development. I have not installed the php4 version on my machine, but it is the php4 version on the host, so during the development process, I have to be careful and careful. Understand the characteristics between them.

1. PHP4 does not have static, private, protect and other modifications, so all these must be removed when the developed program is uploaded to the host!

2. The object call in PHP4 cannot be written as $obj->method_a()->method_b(); but PHP5 can. The meaning of this statement is to call the method_a() method of $obj. It will Return an object and then execute the method_b() method of the object.
Then when I upload it to my host, I have to change all statements like this to

Copy the code The code is as follows:

$tempobj=$obj->method_a();
$tempobj->method_b();

3. Variable parsing in complex strings can be parsed in php5 Object method attributes, etc., such as:

$a="{$db->isconnected}";
And php4 cannot run correctly.
4. In PHP5, you can use construction and destruction magic functions such as:
Copy code The code is as follows:

< ;?php
class MyDestructableClass {
function __construct() {
print "In constructorn";
$this->name = "MyDestructableClass";
}

function __destruct() {
print "Destroying " . $this->name . "n";
}
}

$obj = new MyDestructableClass();
? >

But there is no such thing in php4. Only the function with the same name as the class name is the constructor, and the constructor with the same name as the class name.

php5 adds a lot to php4, such as pdo, etc. php6 may have more extensions (I haven’t tried php6 yet). I think php will become more and more powerful and more and more suitable for WEB-based development. .

A brief discussion on the differences between PHP5 and PHP4:
1. Not 100% backward compatible
Although most of the PHP4 code should be able to run without modification in php5, You should still pay attention to the following changes that are not backward compatible:
There are some new keywords.
strrpos() and strripos() now use the entire string as needle.
Illegal use of string offsets results in E_ERROR instead of E_WARNING. An example of illegal use: $str = ‘abc’; unset($str[0]);.
array_merge() was changed to only accept arrays. If a non-array variable is passed in, an E_WARNING message is emitted for each such argument. Be careful because your code may issue E_WARNINGs like crazy.
The PATH_TRANSLATED server variable is no longer implicitly set in the Apache2 SAPI, contrary to the situation in PHP 4, where if Apache did not generate this value it was set to the same value as the SCRIPT_FILENAME server variable. This modification is to comply with CGI specifications. See the description of $_SERVER['PATH_TRANSLATED'] in the manual for more information. This issue also affects versions of PHP >= 4.3.2.
Tokenizer extension no longer defines T_ML_COMMENT constant. If error_reporting is set to E_ALL, PHP will generate a message. Although T_ML_COMMENT has never been used, it is defined in PHP 4. In PHP 4 and PHP 5 // and are resolved to T_COMMENT constants. But PHPDoc-style comments, parsed by PHP since PHP 5, are recognized as T_DOC_COMMENT.
If variables_order includes "S", $_SERVER should be generated with argc and argv. If the user specifically configures the system not to create $_SERVER, then of course this variable will not exist. The change is that argc and argv are always available in the CLI version regardless of how variables_order is set. Originally, the CLI version does not always generate global variables $argc and $argv.
Objects without attributes are no longer considered "empty".

In some cases classes must be defined before use. This only happens when using some of the new PHP 5 features (such as interfaces). In other cases the behavior remains unchanged.
get_class(), get_parent_class() and get_class_methods() now return the same class/method names as when they were defined (case-sensitive), for older scripts that relied on the previous behavior (class/method names always returned lowercase) Problems may arise. A possible workaround is to search for all these functions in the script and use strtolower().
The case sensitivity changes also apply to the magic constants __CLASS__, __METHOD__ and __FUNCTION__. Its value will be returned strictly according to the name when it was defined (case-sensitive).
ip2long() returns FALSE when passed an illegal IP as argument, no longer -1.

If there are functions defined in the include file, these functions can be used in the main file regardless of whether they are before or after the return() directive. PHP 5 will issue a fatal error if the file is included twice because the function is already defined, while PHP 4 doesn't care about this. Therefore it is recommended to use include_once() instead of checking whether the file has been included and conditionally returning in the included file.
include_once() and require_once() first normalize the path under Windows, so including A.php and a.php will only include the file once.
Example: strrpos() and strripos() now use the entire string as needle
Copy code The code is as follows:

var_dump(strrpos('ABCDEF','DEF')); //int(3)
var_dump(strrpos('ABCDEF','DAF')); //bool(false )
?>
Example: Objects without attributes are no longer treated as "empty"
class test { }
$t = new test();
var_dump(empty($t)); // echo bool(false)
if ($t) {
// Will be executed
}
?>

Example: In some cases, classes must be defined before use
Copy code The code is as follows:

//works with no errors:
$a = new a();
class a {
}
//throws an error:
$a = new b() ;
interface c{
}
class b implements c {
}
?>

2. CLI and CGI
Some changes have been made to CLI and CGI file names in PHP 5. In PHP 5, the CGI version was renamed php-cgi.exe (formerly php.exe), and the CLI version is now in the home directory (formerly cli/php.exe).
PHP 5 introduces a new mode: php-win.exe. This is the same as the CLI version, except php-win doesn't output anything, so no console is provided (no "dos window" flashes on the screen). This behavior is similar to php-gtk.
In PHP 5, the CLI version always generates global variables $argv and $argc regardless of how php.ini is set. Even setting register_argc_argv to off does not affect the CLI.
See command line mode.
3. Migrate the configuration file
Since the name of the ISAPI module has been changed from php4xxx to php5xxx, some modifications to the configuration file are required. CLI and CGI file names have also been changed. Please see the corresponding chapters for more information.
Porting an Apache configuration is extremely easy. Follow the example below to check the changes that need to be made:
Example: Porting the Apache configuration file to PHP 5
# Change the following line: LoadModule php4_module /php/sapi/php4apache2.dll # to this line: LoadModule php5_module /php/php5apache2.dll
If the web server is running PHP in CGI mode, you should note that the name of the CGI version has been changed from php.exe to php-cgi.exe. In Apache, it should be changed as follows:
Example: Port the Apache configuration file to PHP 5, CGI mode
# Change the following line: Action application/x-httpd-php "/php/php.exe" # Change to this line: Action application/x-httpd-php "/php/php-cgi.exe"
In other web servers, you need to modify the name of the CGI or ISAPI module.
4. New functions
PHP 5 has some new functions. Here is the list:
Arrays:
array_combine() - Creates a new array with one array as keys and another array as values ​​
array_diff_uassoc() - Computes the difference of the arrays and uses a user-provided callback function Do additional index checks
array_udiff() - Use callback function to compare data to calculate the difference of arrays
array_udiff_assoc() - Calculate the difference of arrays and do additional index checks. Use callback functions to compare data
array_udiff_uassoc() - Compute array differences and do additional index checks. Data comparison and index checking are done using callback functions
array_walk_recursive() - Recursively use user functions for each member of the array
array_uintersect_assoc() - Calculate the intersection of arrays and do additional index checking. Use callback functions to compare data
array_uintersect_uassoc() - Computes the intersection of arrays and does additional index checking. Both data and indexes are compared using callback functions
array_uintersect() - Computes the intersection of arrays.用回调函数来比较数据
InterBase:
ibase_affected_rows() - 返回前一个查询影响到的行的数目
ibase_backup() - 在服务管理器中发起一个后台任务并立即返回
ibase_commit_ret() - 提交一个事务但不关闭
ibase_db_info() - 请求有关数据库的统计信息
ibase_drop_db() - 删除一个数据库
ibase_errcode() - 返回一个错误代码
ibase_free_event_handler() - 取消一个已注册的事件句柄
ibase_gen_id() - 递增指定的发生器并返回其新值
ibase_maintain_db() - 在数据库服务器上执行一条维护命令
ibase_name_result() - 给结果集指定一个名字
ibase_num_params() - 返回一个准备好的查询的参数数目
ibase_param_info() - 返回一个准备好的查询的参数信息
ibase_restore() - 在服务管理器中发起一个还原任务并立即返回
ibase_rollback_ret() - 回卷一笔事务并保留事务上下文
ibase_server_info() - 请求有关数据库服务器的统计信息
ibase_service_attach() - 连接到服务管理器
ibase_service_detach() - 从服务管理器断开
ibase_set_event_handler() - 注册一个当事件发布时要调用的回调函数
ibase_wait_event() - 等待数据库发布一条事件
iconv:
iconv_mime_decode() - 解码 MIME 头信息字段
iconv_mime_decode_headers() - 一次解码多个 MIME 头信息字段
iconv_mime_encode() - 压缩 MIME 头信息字段
iconv_strlen() - 返回字符串中的字符计数
iconv_strpos() - 在堆栈中找到第一个出现的子串位置
iconv_strrpos() - 在堆栈中找到最后一个出现的子串位置
iconv_substr() - 从字符串中取出一部分
Streams:
stream_copy_to_stream() - 把一个流的数据复制到另一个流
stream_get_line() - 根据给定的分隔符中流中读取一行
stream_socket_accept() - 接受一个由 stream_socket_server() 建立的 socket 连接
stream_socket_client() - 打开一个 Internet 或 Unix 域的 socket 连接
stream_socket_get_name() - 获取本地或远程的 sockets 名字
stream_socket_recvfrom() - 从 socket 获取数据(不管连接是否已经建立)
stream_socket_sendto() - 向 socket 发送一个消息(不管连接是否已经建立)
stream_socket_server() - 建立一个 Internet 或 Unix 域服务器的 socket
Date/Time:
idate() - 将本地进间格式化为整数
date_sunset() - 计算所指定日期和地点的日落时间
date_sunrise() - T计算所指定日期和地点的日出时间
time_nanosleep() - 廷迟执行程若干秒和若干纳秒
Strings:
str_split() - 把一个字符串分割为数组
strpbrk() - 在一字符串中搜索给定的字符集合中的任意一个字符
substr_compare() - 以二进制的形式比较两个字符串,从第一个字符串的 offset 开始,直到到达长度为 length 时结束,可自定义是否大小写敏感比较
Other:
convert_uudecode() - 解码 uuencoded 的字符串
convert_uuencode() - 对字符串进行 uuencode
curl_copy_handle() - 复制一个 cURL 句柄及其所有参数
dba_key_split() - 把一个键分隔为字符串数组
dbase_get_header_info() - 取得 dBase 数据库的头部信息
dbx_fetch_row() - 获取结果集中被设置为 DBX_RESULT_UNBUFFERED 的行
fbsql_set_password() - 修改指定用户的密码
file_put_contents() - 向一个文件内写入字符串
ftp_alloc() - 为准备上传的文件分配空间
get_declared_interfaces() - 以数组的形式返回所有已定义的接品
get_headers() - 获取服务器响应 HTTP 请求时的所有头部信息
headers_list() - 返回所有已发送或准备发送响应头部列表
http_build_query() - 生成一个已经过 URL 编码的请求字符串
image_type_to_extension() - 根据 getimagesize(), exif_read_data(), exif_thumbnail(), exif_imagetype() 所返回的 image-type 取得文件名后缀
imagefilter() - 对图像应用滤镜
imap_getacl() - 获取指定邮箱的 ACL
ldap_sasl_bind() - 使用 SASL 绑定到 LDAP 目录
mb_list_encodings() - 以数组的形式返回所支持的全部字符集
pcntl_getpriority() - 获得任意一个进程的优先级
pcntl_wait() - Waits on or returns the status of a forked child as defined by the waitpid() system call
pg_version() - 返回一个包含客户端、协议和服务器版本的数组
php_check_syntax() - 检查指定文件的语法
php_strip_whitespace() - 返回已经去除注释和空白的源代码
proc_nice() - 修改当前进程的优前级
pspell_config_data_dir() - 修改语言文件的位置
pspell_config_dict_dir() - 修改主要单词列表的位置
setrawcookie() - 发送一个没有经过 url 编码的 cookie 值
scandir() - 列中指定目录中的所有子目录和文件
snmp_read_mib() - Read and split a MIB file in an available MIB tree
sqlite_fetch_column_types() - Return the column types in a table in the form of an array
Note: The API of the Tidy extension library has also been significantly improved Adjustments
5. New commands
PHP 5 introduces some new commands in php.ini. The list is as follows:
mail.force_extra_parameters - Forces the specified parameter additional values ​​to be passed as extra parameters to the sendmail library. These parameters will always replace the 5th parameter of mail(), even in safe mode
register_long_arrays - Allow/disable PHP to register obsolete $HTTP_*_VARS variables
session.hash_function - Choose a hash Column functions (MD5 or SHA-1)
session.hash_bits_per_character - defines how many bits are stored per character (from 4 to 6) when converting binary hash data to a readable format
zend.ze1_compatibility_mode - enabled Zend Engline 1st generation (PHP 4) compatibility mode
6. Database
There are some changes in PHP 5 about databases (MySQL and SQLite).
The MySQL client connection library is no longer bundled in PHP 5 due to authorization and other issues.
There is a new extension library MySQLi (improved version of MySQL), designed to work under MySQL 4.1 and higher.
Since PHP 5, the SQLite extension library is built into PHP. SQLite is an embeddable SQL database engine, not a client connection library used to connect to large database servers (such as MySQL or PostgreSQL). The SQLite library directly reads and writes database files on disk.
7. New Object Model
There is a new object model (Object Model) in PHP 5. The way PHP handles objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were treated the same as primitive types (such as integers and strings). The disadvantage of this method is that semantically the entire object is copied when a variable is assigned a value or passed as a parameter to a method. In the new approach, objects are referenced by handles rather than values ​​(think of handles as identifiers of objects).
Many PHP programmers are simply unaware of this copying quirk of the old object model, so most PHP applications run right out of the box, or with only minor modifications.
See "Classes and Objects" for documentation of the new object model.

Basic knowledge of PHP: Comparison of configuration similarities and differences between PHP4 and PHP5


In the process of configuring php4 or php5, the steps for configuring php4 and 5 are roughly the same , but there are some differences in configuration content. When compiling in environments such as LINUX, generally speaking, as long as the compilation options are correct, the configuration will be correct; when configuring in windows, you need to pay attention to the following differences:
1. php4ts.dll and php5ts.dll The content comes from the Chinese webmaster Information Network (www.chinahtml.com)

This file should be copied to the bin directory of apache or the system directory

2. Modules loaded by the httpd.conf file

An example is as follows:
# For PHP4 + apache1.x.xx
LoadModule php4_module d:/www/webserver/php4/sapi/php4apache.dll
AddType application/x-httpd-php .php content comes from China Webmaster Information Network (www.chinahtml.com)
# For PHP4 + apache2.x.xx
LoadModule php4_module d:/www/webserver/php4/sapi/php4apache2.dll
AddType application/x- httpd-php .php

# where d:/www/webserver/php4 is the directory where php is located.

# For PHP5 + apache1.x.xx
LoadModule php5_module d:/www/webserver/php5/php5apache.dll
AddType application/x-httpd-php .php

# For PHP5 + apache2.x.xx
LoadModule php5_module d:/www/webserver/php5/php5apache2.dll
AddType application/x-httpd-php .php
# where d:/www/ webserver/php5 is the directory where php is located.

3. The way to load mysql is different

In php4 and previous versions, mysql is integrated in php;
In PHP5 (including BETA) version, mysql is as To load a module, you need to set php.ini to load, for example
extension_dir = "D:/www/WebServer/PHP5/ext/"
extension=php_mysql.dl l

In addition, PHP4 , PHP5 requires the support of libmysql.dll in the system directory. If the version is incorrect, even if you set the correct extension_dir and php_mysql.dll parameters, it will cause an error that phpp_mysql.dll cannot be found when apache starts.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324637.htmlTechArticlephp4 There is no static member. Such an error occurs in the php web background. I checked SubPages1.php and did not find the corresponding error. The website is completely normal when tested locally, but it appears after being uploaded to the space...
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