From PHP's deprecated error

Source: Internet
Author: User
Tags deprecated ereg

Discover deprecated problems

Recently completed a project, the basic functions are normal, published to the online. As a result, a large number of errors have been found in the online

A look at PHP's deprecated error, is the lowest level of the kind.
The official PHP manual explains the error levels as follows:

See: Official PHP Instructions

Finding deprecated problems

View the details of the first article,


As can be seen, the error is due to the use of the Eregi function in common.ini.php, which raises the deprecated error.
The problem code is in line 52 of common.ini.php.
View Code:

Phperegi ('. ( [^.] *$) ', $fileName, $ extension);

The resulting error, which is a regular expression that gets the file suffix name.

Analyze deprecated problems

The reason for the error is that PHP does not recommend using the EREGI function to handle regular expressions.
Refer to the official PHP 5.3 compatible documentation, which is described below:

See: Official PHP Instructions

PHP officials point out that PHP5.3 does not recommend using the Eregi function, and it is recommended to use the Preg_match function instead.

Solve deprecated problems

Next, change the eregi to Perg_match, and then modify the regular expression.
The code using Perg_match is as follows:

Phppreg_match ('/. ( [^.] *$)/', $fileName, $ extension);

So the deprecated error is gone.

Study the problem of deprecated

In general, the Deprecated error does not affect the operation even if it is not repaired, but does it affect performance?
Make a comparison test of the error output and turn off the display_error output.
The code is as follows:

Php
   

The result is:
[With Deprecated]processing time:0.51678085327148
[No deprecated]processing time:0.31887912750244

proved that the performance was reduced by one-fold after the error_reporting of the deprecated was turned on. The exact reason is the same as the following notice.
We do another experiment, wrote two PHP programs, one is the existence of deprecated error code, the other is to fix the deprecated code, the code is as follows:

Run up and look at the results:
Trigger deprecated:0.33528900146484
Trigger No deprecated:0.019602060317993

The performance difference between the two is 17.63 times times. After replacing Ereg with Preg_match, not only the deprecated error is gone, but also the performance is greatly improved.
The performance increase is due to the fact that Perl handles regular expressions faster than POSIX.

There are potential compatibility problems for deprecated errors, which should be paid attention to by everyone.
All functions that prompt deprecated are officially deprecated and may not be compatible with new versions of PHP in the future.
The most typical case is that PHP5.5.0 is no longer compatible with mysql_query and mysql_connect.
To ensure that the PHP version is upgraded, the program runs correctly and requires the use of mysqli and PDO to access the database.

  • 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.