Main new features of PHP7.0 I sorted out, new features of php7.0 _ PHP Tutorial

Source: Internet
Author: User
Tags configuration php
The main new features of PHP7.0 and php7.0. The main new features of PHP7.0 I have compiled. Up to now, PHP has released the RC5 version of php7. it is expected that the first official version will be released around May! Now I have sorted out the main new features of PHP 7.0 and new features of PHP.

So far, PHP has officially released the PHP 7 RC5 version. it is expected that the first official version will be released around May! Now, the major features of PHP 7 must have been finalized and won't be changed. Later versions of iterations mainly involve bug fixing and optimization. Let's talk about the new features of php7.0 that we have always been expecting.

1. scalar parameter type declaration

Currently, string, int, float, and Boolean parameters are supported. in the past, only class names, interfaces, arrays, and Callable parameters are supported.
Two styles: Forced conversion mode (default) and strict mode

<?php// Coercive modefunction sumOfInts(int ...$ints){return array_sum($ints);}var_dump(sumOfInts(2, '3', 4.1)); 

2. return type declaration

<?phpfunction 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])); 

3 .?? Operator

?? It is used to replace the scenario where isset is required. this is a syntactic sugar.

<?php// Fetches the value of $_GET['user'] and returns 'nobody'// if it does not exist.$username = $_GET['user'] ?? 'nobody';// This is equivalent to:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';// Coalescing can be chained: this will return the first// defined value out of $_GET['user'], $_POST['user'], and// 'nobody'.$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; 

4. <=> comparison operators

Is to look at the size of the two expression values, three relationships: = return 0, <return-1,> return 1

<?php// Integersecho 1 <=> 1; // 0echo 1 <=> 2; // -1echo 2 <=> 1; // 1// Floatsecho 1.5 <=> 1.5; // 0echo 1.5 <=> 2.5; // -1echo 2.5 <=> 1.5; // 1// Stringsecho "a" <=> "a"; // 0echo "a" <=> "b"; // -1echo "b" <=> "a"; // 1 

5. define supports defining values of the array type

Php 5.6 already supports the CONST syntax to define constants of the array class, and PHP7 supports the define Syntax.

<?phpdefine('ANIMALS', ['dog','cat','bird']);echo ANIMALS[1]; // outputs "cat" 

6. anonymous class

<?phpinterface 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;$app->setLogger(new class implements Logger {public function log(string $msg) {echo $msg;}});var_dump($app->getLogger()); 

7. added the integer division function intp.

Summary:

PHP 7's performance breakthrough has become one of the hottest topics recently. the Official PHP 7.0.0 Beta 2 has been released.

New features

Performance improvement: PHP 7 is twice faster than PHP 5.6

Fully consistent 64-bit support

Removed some old unsupported SAPI (server-side application programming port) and extensions

Added the null join operator (??)

Articles you may be interested in:
  • Win2008 R2 IIS7 PHP 5.4 Environment build graphic tutorial
  • IIS7.5 + PHP5.2.17 + Mysql5.5.16 + Zend3.3.3 under win2008 R2
  • Scheduled execution of PHP script settings for win7 tasks
  • How to install the imagick and imagemagick extensions of php in Windows 7
  • Windows 7 install php php-ssh2 extension tutorial
  • PHP error Allowed memory size of 67108864 bytes exhausted three solutions
  • IIS7, IIS7.5 solution to site slowdown after PHP5.3 upgrade
  • IIS7 PHP configuration diagram (IIS7 + PHP_5.2.17/PHP_5.3.5)
  • 64-bit win7 system configuration php latest development environment (php + Apache + mysql)
  • Php stealth character 65279 (BOM header of UTF-8)
  • Connect PHP to the Oracle database in Win7 64-bit system
  • In-depth analysis of new features of PHP7.0 (five new features)

Major new features of php7.0 and new features of php7.0 so far, PHP has officially released the RC5 version of php7. it is expected that the first official version will be released around May! Now...

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.