Home Backend Development PHP7 Precautions for handling PHP5 to PHP7 in one move

Precautions for handling PHP5 to PHP7 in one move

Jun 08, 2021 am 09:15 AM
php5 php7

This article will introduce to you the precautions from PHP5 to PHP7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Precautions for handling PHP5 to PHP7 in one move

PHP7 is the general trend. PHP7 has more new features, better performance, and higher speed. Moreover, the beta3 of PHP7.0 will be released from August 7 this year, and the RC1 version of PHP7 will be released soon. The pace is getting closer, and more people are learning the new features of PHP7. PHP Academy will serialize the new features of PHP7.

Moreover, some domestic PHPers who like to try new things have already installed PHP7. Let's take a look at what new features PHP7 has.

Today we are going to explain some styles promoted by PHP, and we have disabled some styles in the original PHP4.

1. In order to please ASP programmers when PHP5 was released, PHP prepared all asp_tags to be banned.

There will be no <% %> style in the future, and PHP will no longer support it. style statement.

<script language="php"></script>
Copy after login

2, some things in the syntax style of PHP4 will be completely abandoned in the new PHP7, such as the usage of constructors. PHP7 will prompt an error message: E_DEPRECATED.

<?php
class foo {
    //方法名类名相同的构造函数的用法不再兼容     
    function foo() {         
        echo &#39;I am the constructor&#39;;     
    } 
  }
?>
Copy after login

1. Define defined constants not only support scalars, but also arrays

<?php

define(&#39;PHPXY&#39;, array(
    &#39;凤姐&#39;,
    &#39;芙蓉姐姐&#39;,
    &#39;杨幂是臭脚&#39;
));

echo PHPXY[1]; // 输出的结果是“芙蓉姐姐”
?>
Copy after login

2. When comparing, it supports <=>, which can compare strings and arrays. Integer type.

<?php

// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
Copy after login

Comment: We believe that the actual users are not large, and the usage in actual work will not be very high

3. Mandatory parameter type specification of functions is supported in PHP7

<?php
// Coercive mode
function sumOfInts(int ...$ints)
{
    return array_sum($ints);
}

var_dump(sumOfInts(2, &#39;3&#39;, 4.1));

//本例中会输出9,你想想为什么哟?——因为强制规定为了整型
Copy after login

Comment: function funcName(... parameter) is supported by PHP5.6. Don't think it is a knowledge point in PHP7

4. The return type is also mandatory

function arraysSum(array ...$arrays): array
{
    return array_map(function(array $array): int {
        return array_sum($array);
    }, $arrays);
}

print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
Copy after login

5. A new call method is added to be called externally, and the anonymous function is appended in a shorter way Enter the object and complete the call

class A {private $x = 1;}

// Pre PHP 7 code
$getXCB = function() {return $this->x;};
$getX = $getXCB->bindTo(new A, &#39;A&#39;); // intermediate closure
echo $getX();

// PHP 7+ code
$getX = function() {return $this->x;};
echo $getX->call(new A);
Copy after login

6. The member method can also stipulate that a certain class type must be returned

class A {}
class B extends A {}

class C
{
    public function test() : A
    {
        return new A;
    }
}
Copy after login

We must delete some functions of PHP7.

In the PHP manual, in order to specifically cope with your upgrade, some functions deleted in PHP7 are explained and organized for you. If you use these functions in your project, please search and modify them throughout the project.

1. call_user_method() and call_user_method_array()

2. mcrypt_generic_end() alias in favor of mcrypt_generic_deinit()

3. Deprecated mcrypt_ecb(), mcrypt_cbc() , mcrypt_cfb() and mcrypt_ofb() in favor of mcrypt_decrypt() parameters MCRYPT_MODE_*

4. Deprecated datefmt_set_timezone_id() and IntlDateFormatter::setTimeZoneID() in favor of datefmt_set_timezone() or IntlDateFormatter::setTimeZone()

5. set_magic_quotes_runtime() and its alias function magic_quotes_runtime()

6. set_socket_blocking() is beneficial to its alias function stream_set_blocking()

7. From fast- cgi's dl()

8. T1Lib supports deletion, so delete: imagepsbbox(), imagepsencodefont(), imagepsextendedfont(), imagepsfreefont(), imagepsloadfont(), imagepsslantfont(), imagepstext()

There was a slight delay in the original serialization plan of new features of PHP7. We have translated the official press release of the PHP7 RC1 version. This is the PHP7.0 RC1 version that everyone has been waiting for a long time.

The so-called RC version is the version that will be officially launched soon. (Release Candidate) is a candidate version when used in software. The system platform is the release candidate version. The RC version will not add new features and will mainly focus on debugging.

The PHP development team announced that version PHP 7.0.0 RC 1 is a soon-to-be-available version. You can test in detail and report the problems you encounter to PHP's BUG tracking system.

The address for BUG test submission is: https://bugs.php.net/

1. PHP7 is twice as fast as php 5.6

2. Update Good support for 64-bit operating systems

3. More error support and new error trapping

4. Remove some unsupported functions and unsupported SAPIs and extensions

5. Null coalescing operator (??)

6. Comprehensive comparison operator (<=>)

7. Return type declaration

8. Scalar type declaration

9. Anonymous class

PHP has deleted some functions, two of which are scary:

1. Regular functions of the ereg_* series

2. Mysql_* series of database connection functions

PHP7 completely removes Mysql extension support, and the original mysql_* series of functions will no longer be supported in mysql. Therefore, if your application system still uses the mysql_* series of functions to connect to the database, please upgrade your mysql series of functions as soon as possible.

Let’s take a look at what extensions have been deleted by PHP7:

  • 1. ereg

  • 2. mssql

  • 3. mysql

  • 4. sybase_ct

Alternative processing and solutions:

1. If you want to connect to Microsoft's sql server database, please use the PDO solution.

2. If you use the mysql series of function extensions to connect to the database, please use the more efficient mysql_nd series of functions. . It has higher efficiency

3. If you are using the ereg series, change it as soon as possible.

4. Change sybase_ct to sybase* series

Many friends don’t know what SAPI is, and they don’t know the relationship between SAPI and PHP. In this chapter, while understanding which SAPIs have been deleted in PHP7, you can learn more about the internal processing mechanism of PHP and what are the SAPI is deleted

SAPI refers to the programming interface for specific PHP applications. Just like PC, no matter which operating system is installed, as long as it meets the PC interface specifications, it can run normally on the PC. PHP scripts must There are many ways to execute it, through a web server, directly from the command line, or embedded in other programs.

  • aolserver

  • apache

  • apache_hooks

  • apache2filter

  • caudium

  • continuity

  • isapi

  • milter

  • nsapi

  • phttpd

  • pi3web

  • roxen

  • thttpd

  • tux

  • webjames

The above SAPIs will not be supported.

Recommended learning: php video tutorial

The above is the detailed content of Precautions for handling PHP5 to PHP7 in one move. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php5 and php8 What is the difference between php5 and php8 Sep 25, 2023 pm 01:34 PM

The differences between php5 and php8 are in terms of performance, language structure, type system, error handling, asynchronous programming, standard library functions and security. Detailed introduction: 1. Performance improvement. Compared with PHP5, PHP8 has a huge improvement in performance. PHP8 introduces a JIT compiler, which can compile and optimize some high-frequency execution codes, thereby improving the running speed; 2. Improved language structure, PHP8 introduces some new language structures and functions. PHP8 supports named parameters, allowing developers to pass parameter names instead of parameter order, etc.

How to install mongo extension in php7.0 How to install mongo extension in php7.0 Nov 21, 2022 am 10:25 AM

How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

How to solve the problem when php7 detects that the tcp port is not working How to solve the problem when php7 detects that the tcp port is not working Mar 22, 2023 am 09:30 AM

In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? Apr 02, 2024 pm 07:39 PM

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

How to change port 80 in php5 How to change port 80 in php5 Jul 24, 2023 pm 04:57 PM

How to change port 80 in php5: 1. Edit the port number in the Apache server configuration file; 2. Edit the PHP configuration file to ensure that PHP works on the new port; 3. Restart the Apache server, and the PHP application will start running on the new port. run on the port.

PHP Server Environment FAQ Guide: Quickly Solve Common Problems PHP Server Environment FAQ Guide: Quickly Solve Common Problems Apr 09, 2024 pm 01:33 PM

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to install and deploy php7.0 How to install and deploy php7.0 Nov 30, 2022 am 09:56 AM

How to install and deploy php7.0: 1. Go to the PHP official website to download the installation version corresponding to the local system; 2. Extract the downloaded zip file to the specified directory; 3. Open the command line window and go to the "E:\php7" directory Just run the "php -v" command.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

See all articles