This article will introduce you to the difference between php7 and php5 in one minute. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
1. PHP scalar type and return type declaration
#主要分为两种模式,强制性模式和严格模式declare(strict_types=1)#1表示严格类型校验模式,作用于函数调用和返回语句;0表示弱类型校验模式。
2. NULL coalescing operator
$site = isset($_GET['site']) ? $_GET['site'] : 'wo';#简写成$site = $_GET['site'] ??'wo';
3. Combination budget operator
// 整型比较print( 1 <=> 1);print(PHP_EOL);print( 1 <=> 2);print(PHP_EOL);print( 2 <=> 1);print(PHP_EOL);print(PHP_EOL); // PHP_EOL 为换行符//结果:0-11
4. Constant array
// 使用 define 函数来定义数组define('sites', [ 'Google', 'Jser', 'Taobao']);print(sites[1]);
5. Anonymous class
interface Logger { public function log(string $msg); } class Application { private $logger; public function getLogger(): Logger { return $this->logger; } public function setLogger(Logger $logger) { $this->logger = $logger; } } $app = new Application; // 使用 new class 创建匿名类 $app->setLogger(new class implements Logger { public function log(string $msg) { print($msg); } }); $app->getLogger()->log("我的第一条日志");
6. The Closure::call() method is added, which means binding an anonymous function to the class
<?php class A { private $x = 1; } // PHP 7 之前版本定义闭包函数代码 $getXCB = function() { return $this->x; }; // 闭包函数绑定到类 A 上 $getX = $getXCB->bindTo(new A, 'A'); echo $getX(); print(PHP_EOL); // PHP 7+ 代码 $getX = function() { return $this->x; }; echo $getX->call(new A); ?>
7. CSPRNG (pseudo-random number generator).
PHP 7 通过引入几个 CSPRNG 函数提供一种简单的机制来生成密码学上强壮的随机数。random_bytes() - 加密生存被保护的伪随机字符串。random_int() - 加密生存被保护的伪随机整数。
8, exception
PHP 7 异常用于向下兼容及增强旧的assert()函数。
9, use statement change
#可以导入同一个namespace下的类简写use some\namespace\{ClassA, ClassB, ClassC as C};
10, Session Options
1.session_start()可以定义数组 <?php session_start([ 'cache_limiter' => 'private', 'read_and_close' => true, ]); ?> 2.引入了一个新的php.ini设置(session.lazy_write),默认情况下设置为 true,意味着session数据只在发生变化时才写入。
11. Extensions removed from PHP 7
ereg mssql mysql sybase_ct
Why is the performance of PHP7 improved compared to PHP5?
1. The variable storage bytes are reduced, the memory usage is reduced, and the variable operation speed is improved.
2. The array structure is improved, and the array elements and hash mapping table are allocated in In the same memory, the memory usage is reduced and the CPU cache hit rate is improved
3. The function calling mechanism is improved. By optimizing the parameter transfer link, some instructions are reduced and the execution efficiency is improved
Recommended learning: php video tutorial
The above is the detailed content of Understand the difference between php7 and php5 in one minute. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft