PHP4 no static Members
PHP Web page Background Such a mistake, checked subpages1.php and did not find the corresponding error. The site is completely normal in its own local test, and this error occurs after it has been uploaded to space. Even the verification code is invisible, and similar errors are 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
The server is version 4.0 if there is "public", then "public" will be removed. There is no error, if "public" is defined variable, change "public" to "Var".
Recently in doing a whole station content management system (see home page), in addition, is also a friend of the Office Building Information Management System! Frankly, the development of PHP for more than half a year, experience is not enough, but engaged in the web for a good number of years of seniority. Initial contact with PHP or PHP3,PHP3 does not support the session, there is no surface image object concept, only a large pile of functions! At first it was also wandering through many web scripts, and Asp,php,jsp was already a three-legged one, and of course perl,cgi was too extravagant for a beginner's student at the time. In fact, I liked that big pile of functions at that time, like at that time to learn DOS command, but compared to ASP php3 no session, no face objects, and many small companies are using ASP is not the first choice of PHP reasons, and PHP4 the biggest progress is to join the image of the object of thought , which increases the session management between the server and the client. Now most of the host provider 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 to develop, on my machine has not installed PHP4 version, but on the host is PHP4 version, so the development process, I have to carefully understand the characteristics between them.
1, PHP4 no static,private,protect and so on, so the development of the program uploaded to the mainframe on the host to remove all these!
2, PHP4 in the image call can not be written $obj->method_a ()->method_b (), and PHP5 can, this statement means that the call $obj () method, will return an object, and then execute the object's method_a ( Method
So I upload it to my mainframe and I have to change all of these statements
Copy Code code as follows:
$tempobj = $obj->method_a ();
$tempobj->method_b ();
3, the complex string in the variable resolution in PHP5 can resolve the object's method attributes, such as:
$a = "{$db->isconnected}";
And PHP4 does not run correctly.
4, PHP5 can be used in the construction and destructor magic functions such as:
Copy Code code as follows:
<?php
Class Mydestructableclass {
function __construct () {
Print "in constructor\n";
$this->name = "Mydestructableclass";
}
function __destruct () {
Print "destroying". $this->name. "\ n";
}
}
$obj = new Mydestructableclass ();
?>
In PhP4, only a function with the same name as the class name is a constructor and a constructor with the same name as the class name.
PHP5 also added a lot of php4, such as PDO, PHP6 may have done more extensions (not yet tried 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
Although most of the PHP4 code in PHP5 can be run without modification, you should pay attention to the following backward-compatible changes:
There are some new keywords.
Strrpos () and Strripos () now use the entire string as needle.
Illegal use of string offsets can result in e_error rather than 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.
path_translated Server variables are no longer implicitly set in Apache2 SAPI, as in PHP 4, if Apache does not produce this value, it is set to the same value as the SCRIPT_FILENAME server variable. This modification is intended to comply with the CGI specification. For more information, refer to the $_server[' path_translated ' in the manual. This issue also affects the version of PHP >= 4.3.2.
Tokenizer extensions no longer define T_ml_comment constants. If you set the error_reporting to e_all,php, a message will be generated. Although T_ml_comment has never been used, it is defined in PHP 4. both//And in PHP 4 and PHP 5 are parsed as T_comment constants. But the PHPDoc style annotation, since PHP 5 has been parsed by PHP, is recognized as t_doc_comment.
If the variables_order includes "S", the $_server should be produced with ARGC and argv. If the user specially configured the system does not create $_server, then this variable certainly does not exist. The place to change is that no matter how variables_order is set, argc and argv are always available in the CLI version. 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 occurs only when some of the 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 consistent (case-sensitive) name for the class/method name defined, and may cause problems with old scripts that rely on previous behavior (class/method names always return lowercase). One possible workaround is to search all of these functions in a script and use Strtolower ().
Case-sensitive changes also apply to Magic constants __class__,__method__ and __function__. The values are returned strictly according to the name of the definition (case-sensitive).
Ip2long () returns FALSE when passing in an illegal IP as an argument, no longer-1.
If a function is defined in the containing file, the functions can be used in the primary file and not after the return () instruction. If the file is included two times, PHP 5 emits a fatal error because the function is already defined, and PHP 4 doesn't care. It is therefore recommended that you use Include_once () instead of checking to see if the file is contained and conditionally returned in the include file.
Include_once () and require_once () normalize the paths under Windows, so containing a.php and a.php will only contain the file once.
Instance: Strrpos () and Strripos () now use the entire string as needle
Copy Code code 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) {
would be executed
}
?>
Instance: In some cases the class must be defined before use
Copy Code code as follows:
<?php
Works with no errors:
$a = new A ();
Class A {
}
Throws an error:
$a = new B ();
Interface c{
}
Class B implements C {
}
?>
Ii. CLI and CGI
Some changes were made to the CLI and CGI filenames 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 (previously Cli/php.exe).
A new model has been introduced in PHP 5: Php-win.exe. This is the same as the CLI version, and will not provide a console except that the Php-win does not output anything (the "DOS window" will not be flashed 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 the configuration file
Because the name of the ISAPI module is changed from Php4xxx to php5xxx, you need to make some modifications to the configuration file. The CLI and CGI file names have also been changed. See the appropriate section for more information.
Porting Apache configuration is extremely simple. Check for changes that need to be made, as shown in the following example:
Instance: porting Apache configuration files 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, it should be noted that the name of the CGI version changed from Php.exe to Php-cgi.exe. In Apache, you should change this way:
Instance: porting Apache configuration files 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 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 in the array and uses the callback function provided by the user as an additional index check
Array_udiff ()-Use callback function to compare data to calculate array differences
ARRAY_UDIFF_ASSOC ()-Computes the difference of the array and makes an additional index check. Using callback functions to compare data
ARRAY_UDIFF_UASSOC ()-Computes the difference of the array and makes an additional index check. 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 the array and makes an additional index check. Using callback functions to compare data
ARRAY_UINTERSECT_UASSOC ()-computes the intersection of the array and makes an additional index check. 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 the Service manager and returns immediately
Ibase_commit_ret ()-Commit a transaction but not close
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 the Service manager and returns immediately
Ibase_rollback_ret ()-rolls back a transaction and retains 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 be invoked when the event is published
Ibase_wait_event ()-Waiting for the database to publish an event
Iconv
Iconv_mime_decode ()-Decode MIME header information field
Iconv_mime_decode_headers ()-Decoding multiple MIME header information fields at a time
Iconv_mime_encode ()-Compressed MIME header information field
Iconv_strlen ()-Returns the count of characters in a string
Iconv_strpos ()-Finds the first occurrence of a substring in the stack
Iconv_strrpos ()-Finds the last occurrence of the substring in the stack
ICONV_SUBSTR ()-Remove part from string
Streams:
Stream_copy_to_stream ()-Copy one stream's data to another stream
Stream_get_line ()-Reads a row from the given delimiter stream
Stream_socket_accept ()-Accepts a socket connection created by Stream_socket_server ()
Stream_socket_client ()-Open a socket connection to an Internet or Unix domain
Stream_socket_get_name ()-Gets the local or remote sockets name
Stream_socket_recvfrom ()-Gets the 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 ()-Establish a socket for an Internet or Unix domain server
Date/time:
Idate ()-Format the local into an integer
Date_sunset ()-Calculates the sunset time for the specified date and place
Date_sunrise ()-T calculates the sunrise time of the specified date and place
Time_nanosleep ()-Late execution of the course for several seconds and several nanoseconds
Strings:
Str_split ()-splits a string into arrays
STRPBRK ()-Searches a string for any character in a given set of characters
Substr_compare ()-compares two strings in binary form, starting with offset of the first string until length is reached and can be customized for case sensitive comparisons
Other:
Convert_uudecode ()-Decoding the Uuencoded string
Convert_uuencode ()-Uuencode the string
Curl_copy_handle ()-Copy a curl handle and all its arguments
Dba_key_split ()-Separates a key into an array of strings
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 ()-Modify the password of the specified user
File_put_contents ()-Writes a string to a file
Ftp_alloc ()-Allocate space for files ready 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 ready to send response headers
Http_build_query ()-generates a request string that has been URL-encoded
Image_type_to_extension ()-Exif_imagetype returned according to GetImageSize (), Exif_read_data (), Exif_thumbnail (), Image-type () Get filename suffix
ImageFilter ()-Apply filters to images
Imap_getacl ()-Gets the ACL for the specified mailbox
Ldap_sasl_bind ()-Bind to LDAP directory with SASL
Mb_list_encodings ()-Returns all of the supported character sets as an array
Pcntl_getpriority ()-Get 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 versions
Php_check_syntax ()-Check the syntax of the specified file
Php_strip_whitespace ()-Returns the source code that has been stripped of annotations and blanks
Proc_nice ()-Modify the top level of the current process
Pspell_config_data_dir ()-Modify the location of the language files
Pspell_config_dict_dir ()-Modify the location of the main word list
Setrawcookie ()-Sends a cookie value without a URL encoding
Scandir ()-All subdirectories and files in the specified directory in the column
Snmp_read_mib ()-Read and split a MIB file in an available MIB tree
Sqlite_fetch_column_types ()-Returns the column type in a table as an array
Note: The API for the Tidy extension Library has also made significant adjustments
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 always replace the 5th parameter of mail (), even in safe mode
Register_long_arrays-Allows/disables PHP registration of obsolete $HTTP _*_vars variables
Session.hash_function-Select a hash function (MD5 or SHA-1)
Session.hash_bits_per_character-Defines the number of bits stored in each character when converting binary hash data to readable format (from 4 to 6)
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 authorization and some other issues.
There is a new extension library, mysqli (modified MySQL), designed to work under MySQL 4.1 and later.
Since PHP 5, the SQLite extension library is built into PHP. SQLite is an embeddable SQL database engine, not a client-side connection library used to connect to large database servers (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. Earlier versions of PHP, object handling is the same as the original type (for example, Integer and string). The disadvantage of this approach is that when a variable is assigned or passed as a parameter to a method, the entire object is copied in semantics. In the new method, the object is referenced by a handle instead of a value (you can treat the handle as an identifier for an object).
Many PHP programmers are unaware of this copy quirk of the old object model, so most PHP applications can be run with or only minor modifications.
The documentation for the new object model is shown in classes and objects.
basic knowledge of PHP: Similarities and differences between PHP4 and PHP5 configurations
In the process of configuring PHP4 or PHP5, the steps of php4,5 configuration are roughly the same, but there are some differences in configuration content. In Linux and other environments, in general, as long as the correct compilation options, configuration is correct; In Windows configuration you need to be aware of the following differences:
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 the system directory.
2. httpd.conf File loaded Modules
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 resides.
# 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 resides.
3. Different ways to load MySQL
In PhP4 and previous versions, MySQL was integrated into PHP;
In PHP5 (including beta) versions, 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 all need the system directory Libmysql.dll support, if the version is incorrect, even if you set the correct extension_dir and Php_mysql.dll parameters, will also cause the Apache boot when prompted Phpp_ Mysql.dll the error that cannot be found.