Php4 has no static members
The following error occurs in the php webpage background. The error message "SubPages1.php" is not found. This error occurs when the website is tested locally. The verification code is invisible. For example, 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 version is 4.0, "public" is removed. No error occurs. If "public" is the definition variable, change "public" to "var ".
Recently, I am working on a content management system for the entire site (see the homepage of this site). I am also working on a friend's office information management system! To be honest, I have used php for development for more than half a year. I have little experience and have been engaged in WEB development for several years. When I first came into contact with php, it was still php3. php3 does not support session, nor does it have the concept of a face object. There are only a lot of functions! Originally, it was stuck in a lot of web scripts. asp, php, and jsp were already three feet at the top. Of course, perl and cgi were too luxurious for students who were still beginners at that time. In fact, at that time, I also liked the many functions, just like the dos command at that time. But compared with asp, php3 has no session and no face object, many small companies are using asp, Which is why php is not selected at first. The biggest improvement of php4 is to add the idea of face object and increase session management between servers and clients. At present, most of the domestic host providers are still on the php4 version, but php5 can be said to be a really meaningful language!
Therefore, php 5 is used for development. No php4 version is installed on my machine, but it is a php4 version on the host. Therefore, I have to be careful during the development process, carefully understand the features between them.
1. PHP4 does not have static, private, protect, and other modifiers. Therefore, the developed program will be uploaded to the host and all of these will be removed!
2. In PHP4, image calls cannot be written as $ obj-> method_a ()-> method_ B (). In PHP5, this statement is used to call $ obj's method_a () method, returns an object and then executes the method_ B () method of the object.
So when I upload it to my host, I have to change all the statementsCopy codeThe Code is as follows: $ tempobj = $ obj-> method_a ();
$ Tempobj-> method_ B ();
3. In variable parsing of complex strings, the method attributes of objects can be parsed in php5, for example:
$ A = "{$ db-> isconnected }";
Php4 cannot run correctly.
4. You can use constructor and destructor magic functions in PHP5, for example:Copy codeThe Code is as follows: <? Php
Class MyDestructableClass {
Function _ construct (){
Print "In constructor \ n ";
$ This-> name = "MyDestructableClass ";
}
Function _ destruct (){
Print "Destroying". $ this-> name. "\ n ";
}
}
$ Obj = new MyDestructableClass ();
?>
Php4 does not. 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 has also increased a lot in php4, such as pdo. php6 may have made more extensions (php6 has not been tried yet), and php will become more powerful, more and more suitable for WEB-based development.
Differences between PHP5 and PHP4:
I. Not 100% backward compatible
In php5, although most PHP 4 code can be run without modification, you should pay attention to the following incompatible changes:
With some new keywords.
Strrpos () and strripos () now use the entire string as the needle.
Invalid string offset causes E_ERROR instead of E_WARNING. An example of invalid use: $ str = 'abc'; unset ($ str [0]);.
Array_merge () is changed to accept only arrays. If a non-array variable is passed, an E_WARNING message is sent for each of these parameters. Be careful because your code may send E_WARNING crazy.
The PATH_TRANSLATED server variable is no longer implicitly set in Apache2 SAPI, which is the opposite of PHP 4. If Apache does not generate this value, it is set to the same value as the SCRIPT_FILENAME server variable. This modification is intended to comply with CGI specifications. For more information, see $ _ SERVER ['path _ TRANSLATED. This problem also affects PHP> = 4.3.2.
The Tokenizer extension no longer defines the T_ML_COMMENT constant. If error_reporting is set to E_ALL, PHP generates a message. Although T_ML_COMMENT has never been used, it is defined in PHP 4. In PHP 4 and PHP 5, // and are parsed as T_COMMENT constants. However, PHPDoc-style comments are parsed by PHP 5 and recognized as T_DOC_COMMENT.
If variables_order includes "S", $ _ SERVER should be generated with argc and argv. If you do not create $ _ SERVER in the special configuration system, this variable does not exist. Regardless of how variables_order is set, argc and argv are always available in the CLI version. Originally, CLI does not always generate global variables $ argc and $ argv.
Objects without attributes are no longer considered "empty ".
In some cases, the class must be defined before use. This only happens when some new PHP 5 features (such as interfaces) are used. In other cases, the behavior remains unchanged.
Get_class (), get_parent_class (), and get_class_methods (). Currently, the class/method names returned are the same as the names in the definition (case sensitive ), old scripts that depend on previous behaviors (Class/method names always return lower-case characters) may cause problems. One possible solution 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 values are returned (case sensitive) according to the defined name ).
Ip2long () returns FALSE when an invalid IP address is passed as a parameter, instead of-1.
If a function is defined in an include file, these functions can be used in the main file, regardless of whether they are before or after the return () command. If the file is contained twice, PHP 5 will send a fatal error because the function has been defined, and PHP 4 does not care about this. Therefore, we recommend that you use include_once () instead of checking whether the file is included or whether conditional responses are returned in the contained file.
Include_once () and require_once () are normalized in Windows. Therefore, A. php and a. php files are included only once.
Instance: strrpos () and strripos () now use the entire string as the needleCopy codeThe Code is as follows: <? Php
Var_dump (strrpos ('abcdef', 'def'); // int (3)
Var_dump (strrpos ('abcdef', 'daf'); // bool (false)
?>
Instance: objects without attributes are no longer treated as "empty"
<? Php
Class test {}
$ T = new test ();
Var_dump (empty ($ t); // echo bool (false)
If ($ t ){
// Will be executed
}
?>
Instance: in some cases, the class must be defined before use.Copy codeThe Code is as follows: <? Php
// Works with no errors:
$ A = new ();
Class {
}
// Throws an error:
$ A = new B ();
Interface c {
}
Class B implements c {
}
?>
Ii. CLI and CGI
In PHP 5, the names of CLI and CGI files have been changed. In PHP 5, the CGI version was renamed to php-cgi.exe (previously php.exe), and now the main directory is the CLI version (previously cli/php.exe ).
PHP 5 introduces a new mode: php-win.exe. This is the same as the CLI version. Only php-win does not output any content, so the console is not provided (the "dos window" is not flashed 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. CLI is not affected even if register_argc_argv is set to off.
See command line mode.
3. Port the configuration file
The ISAPI Module name has been changed from php4xxx to php5xxx. Therefore, you need to modify the configuration file. The names of CLI and CGI files have also been changed. For more information, see the relevant chapter.
Porting Apache configuration is extremely simple. Check the changes as follows:
Instance: port the Apache configuration file to PHP 5.
# Change LoadModule php4_module/php/sapi/php4apache2. dll # To this line: LoadModule php5_module/php/php5apache2. dll
If the web server runs PHP in CGI Mode, note that the CGI version name is changed from php.exe to php-cgi.exe. In Apache, you should change it like this:
Instance: Port Apache configuration file to PHP 5, CGI Mode
# Change the following 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 CGI or ISAPI Module name.
4. New Functions
PHP 5 has some new functions. The following is a list:
Arrays:
Array_combine ()-use an array as the key name, and use another array as the value to create a new array
Array_diff_uassoc ()-calculate the differences between arrays and use the callback function provided by the user for additional index checks.
Array_udiff ()-use the callback function to compare data to calculate array differences
Array_udiff_assoc ()-calculate the differences between arrays and perform additional index checks. Use callback functions to compare data
Array_udiff_uassoc ()-calculate the differences between arrays and perform additional index checks. Data comparison and index check are completed using callback functions.
Array_walk_recursive ()-recursively uses user functions for each member of the array
Array_uintersect_assoc ()-calculates the intersection of arrays and performs additional index checks. Use callback functions to compare data
Array_uintersect_uassoc ()-calculates the intersection of arrays and performs additional index checks. Data and indexes are compared using callback functions.
Array_uintersect ()-calculates the intersection of arrays. Use callback functions to compare data
InterBase:
Ibase_affected_rows ()-returns the number of rows affected by the previous query.
Ibase_backup ()-start a background task in the Service Manager and return immediately
Ibase_commit_ret ()-Submit a transaction but do not close it
Ibase_db_info ()-request statistics about the database
Ibase_drop_db ()-delete a database
Ibase_errcode ()-an error code is returned.
Ibase_free_event_handler ()-cancels a registered event handle
Ibase_gen_id ()-increments the specified generator and returns its new value
Ibase_maintain_db ()-execute 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 of a prepared query.
Ibase_restore ()-start a restoration task in the Service Manager and return immediately
Ibase_rollback_ret ()-rolls back a transaction and retains the transaction Context
Ibase_server_info ()-request statistics on database servers
Ibase_service_attach ()-connect to the Service Manager
Ibase_service_detach ()-Disconnect from Service Manager
Ibase_set_event_handler ()-registers a callback function to be called when an event is published.
Ibase_wait_event ()-Wait for the database to release an event
Iconv:
Iconv_mime_decode ()-decode the MIME header information field
Iconv_mime_decode_headers ()-Decode multiple MIME header information fields at a time
Iconv_mime_encode ()-compresses MIME header information fields
Iconv_strlen ()-returns the string's Character Count
Iconv_strpos ()-locate the first substring position in the stack
Iconv_strrpos ()-locate the position of the last substring in the stack
Iconv_substr ()-extract part of the string
Streams:
Stream_copy_to_stream ()-copy data from one stream to another
Stream_get_line ()-read a row from the specified delimiter
Stream_socket_accept ()-accept a socket connection established by stream_socket_server ()
Stream_socket_client ()-open a socket connection to the Internet or Unix domain
Stream_socket_get_name ()-Get the local or remote sockets name
Stream_socket_recvfrom ()-obtain data from the socket (no matter whether the connection is established or not)
Stream_socket_sendto ()-send a message to the socket (no matter whether the connection is established or not)
Stream_socket_server ()-create an Internet or Unix domain server socket
Date/Time:
Idate ()-format the local feed as an integer
Date_sunset ()-calculates the Sunset Time of the specified date and location
Date_sunrise ()-T calculates the sunrise time of the specified date and location
Time_nanosleep ()-interval of 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 format, starting from the offset of the first string until it ends when the length is length. You can customize whether the string is case sensitive.
Other:
Convert_uudecode ()-decodes uuencoded strings
Convert_uuencode ()-uuencode the string
Curl_copy_handle ()-copy a cURL handle and all its parameters
Dba_key_split ()-separates a key into a String Array
Dbase_get_header_info ()-obtains the header information of the dBase database.
Dbx_fetch_row ()-rows in which the result set is set to DBX_RESULT_UNBUFFERED
Fbsql_set_password ()-Modify the password of a specified user
File_put_contents ()-write a string to a file
Ftp_alloc ()-allocate space for the files to be uploaded
Get_declared_interfaces ()-returns all defined products in the form of arrays.
Get_headers ()-Get all header information when the server responds to an HTTP request
Headers_list ()-returns the list of all sent or prepared Response Headers
Http_build_query ()-generate a URL-encoded request string
Image_type_to_extension ()-Get the filename suffix according to the image-type returned by getimagesize (), exif_read_data (), exif_thumbnail (), exif_imagetype ()
Imagefilter ()-apply a filter to the image
Imap_getacl ()-Get the ACL of the specified mailbox
Ldap_sasl_bind ()-use SASL to bind to the LDAP directory
Mb_list_encodings ()-returns all supported character sets in the form of Arrays
Pcntl_getpriority ()-obtain the priority of any 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 version.
Php_check_syntax ()-check the syntax of the specified file
Php_strip_whitespace ()-return source code that has removed comments and spaces
Proc_nice ()-Modify the prefix of the current process
Pspell_config_data_dir ()-Modify the location of the language file
Pspell_config_dict_dir ()-Modify the location of the main word list
Setrawcookie ()-send a cookie value without url Encoding
Scandir ()-specify all subdirectories and files in the directory in the column
Snmp_read_mib ()-read and split an MIB file in an available MIB Tree
Sqlite_fetch_column_types ()-returns the column type in a table as an array.
Note: The Tidy extension library API has also been significantly adjusted
V. New commands
PHP 5 introduces some new commands in php. ini. The list is as follows:
Mail. force_extra_parameters-the added value of the specified parameter is forcibly transferred as an additional parameter to the sendmail database. These parameters always replace the 5th parameters of mail (), even in Safe Mode
Register_long_arrays-Allow/disable PHP from registering outdated $ HTTP _ * _ VARS Variables
Session. hash_function-select a hash function (MD5 or SHA-1)
Session. hash_bits_per_character-defines the number of characters in each character when converting binary hash data to readable format (from 4 to 6)
Zend. zeend 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.
PHP 5 is no longer bound to the MySQL client connection library because of authorization and other problems.
There is a new extension library MySQLi (improved version of MySQL) designed to work under MySQL 4.1 and later versions.
Since PHP 5, the SQLite extension library is built in PHP. SQLite is an SQL database engine that can be embedded, not a Client Connection database used to connect to large database servers (such as MySQL or PostgreSQL. SQLite database directly reads and writes database files on the disk.
VII. New Object Model
PHP 5 has a new Object Model ). PHP has completely rewritten the way to process objects, allowing better performance and more features. In earlier versions of PHP, the object processing method is the same as that of the original type (such as integer and string. The disadvantage of this method is that when a variable is assigned or passed as a parameter to the method, the entire object is copied in semantics. In the new method, an object is referenced by a handle instead of a value (the handle can be treated as an object identifier ).
Many PHP programmers are not aware of the copy quirks of the old object model, so most PHP applications can run with them, or only make small changes.
For the document of the New object model, see "class and object ".
Basic PHP knowledge: Comparison of PHP4 and PHP5 configurations
In the process of configuring php4 or php5, the configuration steps of php4 and 5 are roughly the same, but there are some differences in the configuration content. Compile in LINUX and other environments. In general, the configuration is correct as long as the compilation options are correct. In windows configuration, pay attention to the following differences:
1. The content of php4ts. dll and php5ts. dll comes from www.chinahtml.com)
This file must be copied to the bin directory of apache or the system directory.
2. httpd. conf file loaded Module
Example:
# For PHP4 + apache1.x. xx
LoadModule php4_module d:/www/webserver/php4/sapi/php4apache. dll
AddType application/x-httpd-php. php content comes from the Chinese 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 earlier versions, mysql is integrated into php;
In PHP5 (including BETA), mysql is loaded as a module, and php. ini needs to be set for loading. For example:
Extension_dir = "D:/www/WebServer/PHP5/ext /"
Extension = php_mysql.dl l
In addition, both PHP4 and PHP5 require libmysql in the system directory. dll support. if the version is incorrect, even if you have set the extension_dir and php_mysql.dll parameters correctly, the error phpp_mysql.dll cannot be found during apache startup.