Summary of differences between PHP4 and PHP5 (configuration similarities and differences) _php tutorial

Source: Internet
Author: User
Tags parse error php basics sapi sunrise time domain server
PHP4 no static Members

PHP Web page in the background this error, checked subpages1.php and did not find the corresponding error. The site in its own local testing is completely normal, to the space after the error occurred. Even the verification code is not visible, similar errors have 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", then "public" is removed. There is no error, if "Public" is the definition variable, change "public" to "Var".

Recently doing an entire station content management system (see the homepage of this site), in addition to do a friend of the Office Building Information Management System! To be honest, the development of PHP for more than half a year, experience is not enough, but the length of the web work has been a good number of years. When the initial contact with PHP or PHP3,PHP3 does not support the session, there is no concept of face-like objects, only a lot of functions! Originally also in a lot of web scripts wandering, asp,php,jsp is already a three-legged top, of course perl,cgi for the students at that time is too extravagant for beginners. In fact, at that time also like that a lot of functions, like learning DOS command, but compared to the ASP PhP3 no session, no face object, and many small companies in the use of ASP is not the first reason to choose PHP, and PHP4 The greatest progress is to add the idea of the object of the face , which increases session management between the server and the client. Now the majority of domestic host providers still stay in the PHP4 version, but PHP5 can be said to be the real meaning of a bit of the language!

So, back to PHP is to use PHP5 development, in my machine has not installed PHP4 version, but on the host is the PHP4 version, so in the development process, I have to carefully, seriously understand the characteristics between them.

1, PHP4 no static,private,protect and so on, so the development of the program to upload to the host to get rid of all these!

2, PHP4 in the image call can not be written $obj->method_a ()->method_b (), and PHP5 can, this sentence means to call the $obj () method, will return an object, and then execute the object's method_a ( Method
Then I upload it to my console and I have to change all of that to
Copy CodeThe code is as follows:
$tempobj = $obj->method_a ();
$tempobj->method_b ();

3, the complex string in the variable parsing PHP5 can parse the object's method properties, such as:

$a = "{$db->isconnected}";
And PHP4 does not work correctly.
4. PHP5 can be used to construct and deconstruct magic functions such as:
Copy CodeThe code is as follows:
Class Mydestructableclass {
function __construct () {
Print "in constructor\n";
$this->name = "Mydestructableclass";
}

function __destruct () {
Print "destroying". $this->name. "\ n";
}
}

$obj = new Mydestructableclass ();
?>

In PhP4, only functions with the same name as the class name are constructors, and constructors with the same name as the class name.

PHP5 on the PHP4 also added a lot, such as PDO, PHP6 may have done more expansion (now not trial PHP6), think PHP will be more powerful, more and more suitable for web-based development.

a brief discussion on the difference between PHP5 and PHP4:
One, not 100% backward compatible
In PhP5, although most PHP4 code should work without modification, you should be aware of the following non-compatible changes:
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 () is changed to accept only arrays. If you pass in a non-array variable, a e_warning message is emitted for each of these parameters. Be careful because your code may be frantically emitting e_warning.
The path_translated server variable is no longer implicitly set in the Apache2 SAPI, which, contrary to the case in PHP 4, is set to the same value as the SCRIPT_FILENAME server variable if Apache does not produce this value. This modification is intended to comply with the CGI specification. For more information, refer to $_server[' path_translated ' in the manual. This issue also affects the version of PHP >= 4.3.2.
The tokenizer extension no longer defines T_ml_comment constants. If you set error_reporting to e_all,php, a message will be generated. Although T_ml_comment has never been used before, it is defined in PHP 4. In PHP 4 and PHP 5//And both are resolved to T_comment constants. But PHPDoc style comments, since PHP 5 has been parsed by PHP, is recognized as t_doc_comment.
If Variables_order includes "S", $_server should be produced with ARGC and argv. If the user specially formulated the system does not create $_server, then this variable certainly does not exist. The place to 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 produce global variables $ARGC and $ARGV.
Objects without attributes are no longer treated as "empty".

In some cases the class must be defined before it is used. This happens only when some new features of PHP 5 (such as interfaces) are used. In other cases the behavior has not changed.
Get_class (), Get_parent_class (), and Get_class_methods () now return a class/method name that is consistent with the definition (case-sensitive), and may cause problems for older scripts that rely on previous behavior (class/method names always return lowercase). One possible workaround is to search all these functions in the script and use Strtolower ().
Case-sensitive changes also apply to Magic constants __class__,__method__ and __function__. The value is returned strictly by the name defined (case-sensitive).
Ip2long () returns FALSE when passed into an illegal IP as a parameter, no longer is-1.

If there are function definitions in the include file, these functions can be used in the main file, regardless of whether before or after the return () directive. If the file is included two times, PHP 5 will make a fatal error because the function is already defined, and PHP 4 doesn't matter. It is therefore recommended to use include_once () instead of checking to see if the file is included and conditionally returned in the included file.
Include_once () and require_once () normalize the path under Windows, so including a.php and a.php will only include the file once.
Examples: Strrpos () and Strripos () now use the entire string as needle
Copy CodeThe code is as follows:
Var_dump (Strrpos (' ABCDEF ', ' DEF ')); Int (3)
Var_dump (Strrpos (' ABCDEF ', ' DAF ')); BOOL (FALSE)
?>
Example: An object without attributes is no longer treated as "empty"
Class Test {}
$t = new test ();
Var_dump (Empty ($t)); echo bool (FALSE)
if ($t) {
would be executed
}
?>

Example: In some cases the class must be defined before use
Copy CodeThe 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 {
}
?>

Second, CLI and CGI
The CLI and CGI file names have been changed in PHP 5. In PHP 5, the CGI version was renamed Php-cgi.exe (formerly Php.exe), and now the CLI version is in the home directory (formerly Cli/php.exe).
PHP 5 introduces a new pattern: Php-win.exe. This is the same as the CLI version, except that Php-win does not output anything, so the console will not be available (the "DOS window" will not flash on the screen). This behavior is similar to PHP-GTK.
In PHP 5, the CLI version always produces 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.
Iii. Porting configuration Files
Since the name of the ISAPI module has changed from Php4xxx to Php5xxx, the configuration file needs to be modified. The CLI and CGI filenames have also been changed. For more information, please see the appropriate section.
Porting the Apache configuration is extremely straightforward. Take the following example to check for changes that need to be made:
Example: Porting Apache configuration files to PHP 5
# put the following line: LoadModule Php4_module/php/sapi/php4apache2.dll # changed to this line: LoadModule Php5_module/php/php5apache2.dll
If the Web server is running PHP in CGI mode, be aware that the CGI version changed from Php.exe to Php-cgi.exe. In Apache, you should change this:
Example: Porting Apache config file to PHP 5,cgi mode
# Change this line: Action application/x-httpd-php "/php/php.exe" # 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.
Iv. new functions
PHP 5 has some new functions. Here is the list:
Arrays:
Array_combine ()-use an array as the key name, and another array to create a new array as a value
ARRAY_DIFF_UASSOC ()-Computes the difference of an array and uses the user-supplied callback function for additional index checking
Array_udiff ()-compares data with a callback function to calculate the difference of an array
ARRAY_UDIFF_ASSOC ()-Calculates the difference in the array and makes additional index checks. Using callback functions to compare data
ARRAY_UDIFF_UASSOC ()-Calculates the difference in the array and makes additional index checks. Data comparisons and index checking are done using callback functions.
Array_walk_recursive ()-Recursive use of user functions for each member of the array
ARRAY_UINTERSECT_ASSOC ()-computes the intersection of an array and makes additional index checks. Using callback functions to compare data
ARRAY_UINTERSECT_UASSOC ()-computes the intersection of an array and makes additional index checks. Data and indexes are compared using callback functions.
Array_uintersect ()-computes the intersection of the array. Using callback functions to compare data
InterBase:
Ibase_affected_rows ()-Returns the number of rows affected by the previous query
Ibase_backup ()-Initiates a background task in Service Manager and returns immediately
Ibase_commit_ret ()-Commit a transaction without closing
Ibase_db_info ()-Request statistical information about the database
ibase_drop_db ()-Delete a database
Ibase_errcode ()-Returns an error code
Ibase_free_event_handler ()-Cancels a registered event handle
ibase_gen_id ()-increments the specified generator and returns its new value
IBASE_MAINTAIN_DB ()-Executes a maintenance command on the database server
Ibase_name_result ()-Specify a name for the result set
Ibase_num_params ()-Returns the number of parameters for a prepared query
Ibase_param_info ()-Returns the parameter information for a prepared query
Ibase_restore ()-Initiates a restore task in Service Manager and returns immediately
Ibase_rollback_ret ()-rolls back a transaction and preserves the transaction context
Ibase_server_info ()-Request statistics about the database server
Ibase_service_attach ()-Connect to Service Manager
Ibase_service_detach ()-Disconnect from service Manager
Ibase_set_event_handler ()-Registers a callback function to invoke when an event is published
Ibase_wait_event ()-Wait for the database to publish an event
Iconv
Iconv_mime_decode ()-Decodes the MIME header information field
Iconv_mime_decode_headers ()-Decodes multiple MIME header information fields at once
Iconv_mime_encode ()-Compress MIME header information fields
Iconv_strlen ()-Returns the count of characters in a string
Iconv_strpos ()-Finds the first occurrence of a substring position in the stack
Iconv_strrpos ()-Finds the last occurrence of the substring position in the stack
ICONV_SUBSTR ()-Remove part of the string
Streams:
Stream_copy_to_stream ()-copy data from one stream to another stream
Stream_get_line ()-Reads a row according to the given delimiter stream
Stream_socket_accept ()-Accepts a socket connection established by Stream_socket_server ()
Stream_socket_client ()-Open a socket connection for an Internet or Unix domain
Stream_socket_get_name ()-Gets the local or remote sockets name
Stream_socket_recvfrom ()-gets data from the socket (regardless of whether the connection has been established)
Stream_socket_sendto ()-sends a message to the socket (regardless of whether the connection has been established)
Stream_socket_server ()-Set up a socket for an Internet or Unix domain server
Date/time:
Idate ()-Formats the local into an integer
Date_sunset ()-Calculates the sunset time for the specified date and place
Date_sunrise ()-T calculates the sunrise time for the specified date and place
Time_nanosleep ()-Late execution process several seconds and several nanoseconds
Strings:
Str_split ()-splits a string into arrays
STRPBRK ()-Searches a string for any character in a given character set
Substr_compare ()-compares two strings in binary form, starting with offset of the first string, until the end of length is reached, and can be customized for case sensitive comparisons
Other:
Convert_uudecode ()-Decodes the uuencoded string
Convert_uuencode ()-Uuencode the string
Curl_copy_handle ()-Copies a CURL handle and all its arguments
Dba_key_split ()-Separates a key into a string array
Dbase_get_header_info ()-Get header information for dBase database
Dbx_fetch_row ()-Gets the row that is set to dbx_result_unbuffered in the result set
Fbsql_set_password ()-modifies the password of the specified user
File_put_contents ()-Writes a string to a file
Ftp_alloc ()-Allocate space for the file to be uploaded
Get_declared_interfaces ()-Returns all defined items as an array
Get_headers ()-Gets all header information when the server responds to an HTTP request
Headers_list ()-Returns a list of all sent or prepared response headers
Http_build_query ()-generates a request string that has been URL encoded
Image_type_to_extension ()-According to GetImageSize (), Exif_read_data (), Exif_thumbnail (), Exif_imagetype () returned by Image-type Get filename suffix
ImageFilter ()-Apply a filter to an image
Imap_getacl ()-Gets the ACL for the specified mailbox
Ldap_sasl_bind ()-Bind to LDAP directory using SASL
Mb_list_encodings ()-Returns all of the supported character sets in the form of an array
Pcntl_getpriority ()-Gets the priority of any one process
Pcntl_wait ()-Waits on or returns the status of a forked child as defined by the Waitpid () system call
Pg_version ()-Returns an array containing the client, protocol, and server versions
Php_check_syntax ()-Check the syntax of the specified file
Php_strip_whitespace ()-Returns the source code that has been stripped of comments and blanks
Proc_nice ()-modifies the top level of the current process
Pspell_config_data_dir ()-Modify the location of the language file
Pspell_config_dict_dir ()-modifies the location of the main word list
Setrawcookie ()-Sends a cookie value that is not URL encoded
Scandir ()-All subdirectories and files in the specified directory in the column
Snmp_read_mib ()-Read and sub-board an MIB file in one of the available MIB trees
Sqlite_fetch_column_types ()-Returns the column type in a table as an array
Note: The API for the Tidy extension library has also been significantly adjusted
V. New directives
PHP 5 introduced a number of new directives in php.ini. The list is as follows:
Mail.force_extra_parameters-Forces the specified parameter value to be passed to the SendMail library as an additional parameter. These parameters will always replace the 5th parameter of mail (), even in safe mode
Register_long_arrays-Allow/disallow PHP to register obsolete $HTTP _*_vars variables
Session.hash_function-Select a hash function (MD5 or SHA-1)
Session.hash_bits_per_character-Defines how many bits (from 4 to 6) are stored in each character when converting binary hash data to a readable format
Zend.ze1_compatibility_mode-Enable Zend Engline 1 generation (PHP 4) Compatibility mode
Vi. Database
There are some changes to the database (MySQL and SQLite) in PHP 5.
The MySQL Client connection library is no longer bound in PHP 5 because of licensing and some other issues.
A new extension library, mysqli (improved MySQL), was designed to work under MySQL 4.1 and later.
Since PHP 5, the SQLite extension library is built into PHP. SQLite is an embedded SQL database engine, not a client connection library used to connect a large database server (such as MySQL or PostgreSQL). The SQLite library directly reads and writes the database files on the disk.
Vii. New Object Model
There is a new object model in PHP 5. The way PHP handles objects is completely rewritten, allowing for better performance and more features. Previous versions of PHP had the same object handling as the original type (for example, Integer and string). The disadvantage of this method is that when a variable is assigned or passed as a parameter to a method, the entire object is copied semantically. In the new method, the object is referenced by a handle, not a value (the handle can be treated as an identifier of the object).
Many PHP programmers simply don't realize the quirks of this copy of the old object model, so most PHP applications can run, or only make minor changes.
The documentation for the new object model is shown in classes and objects.

PHP Basics: Comparison of configurations between PHP4 and PHP5


During the configuration of PhP4 or PHP5, the steps for php4,5 configuration are roughly the same, but there are some differences in configuration content. In Linux and other environments to compile, in general, as long as the compilation of the correct options, the configuration is correct, in Windows configuration you need to pay attention to the following different points:
1. Php4ts.dll and Php5ts.dll content from China Webmaster Information Network (www.chinahtml.com)

This file will be copied to the Apache Bin directory or under the system directory.

2. httpd.conf File Loading module

Examples are as follows:
# for PHP4 + apache1.x.xx
LoadModule Php4_module D:/www/webserver/php4/sapi/php4apache.dll
AddType application/x-httpd-php. PHP content 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. Different ways to load MySQL

In PhP4 and previous versions, MySQL was integrated in PHP;
In the PHP5 (including beta) version, MySQL is loaded as a module and needs to be set php.ini to load, for example
Extension_dir = "d:/www/webserver/php5/ext/"
Extension=php_mysql.dl L

In addition, PHP4,PHP5 need the system directory of Libmysql.dll support, if the wrong version, even if you set the correct extension_dir and Php_mysql.dll parameters, will also cause Apache boot time prompt phpp_ Mysql.dll the error that could not be found.

http://www.bkjia.com/PHPjc/324637.html www.bkjia.com true http://www.bkjia.com/PHPjc/324637.html techarticle php4 no static Member PHP Web page in the background such errors, checked subpages1.php did not find the corresponding error. The site in its own local testing is completely normal, into space after the appearance of ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.