The main new features of PHP 7.0 that I compiled, the new features of php7.0_PHP tutorial

WBOY
Release: 2016-07-12 09:01:16
Original
1000 people have browsed it

The main new features of PHP 7.0 that I compiled, the new features of php7.0

So far, PHP has officially released the RC5 version of php7, which is expected to be released around November Release the first official version! Now, the major features of php7 have definitely been finalized and there will be no more changes. The iterations of some subsequent versions are mainly bug fixes, optimizations and the like. Let’s talk about the new features of php7.0 that we have been looking forward to.

1. Scalar parameter type declaration

Now supports string, integer, float, and bool parameter declarations. Previously, only class names, interfaces, arrays, and Callables were supported
Two styles: forced conversion mode (default) and strict mode

<&#63;php
// Coercive mode
function sumOfInts(int ...$ints)
{
return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1)); 
Copy after login

2. Return type declaration

<&#63;php
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

3.??Operator

?? is used to replace isset when isset is required. This is a syntactic sugar.

<&#63;php
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] &#63;&#63; 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) &#63; $_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'] &#63;&#63; $_POST['user'] &#63;&#63; 'nobody'; 
Copy after login

4.<=> Comparison operator

It depends on the size of the two expression values, three relationships: = returns 0, < returns -1, > returns 1

<&#63;php
// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
// Floats
echo 1.5 <=> 1.5; // 0
echo 1.5 <=> 2.5; // -1
echo 2.5 <=> 1.5; // 1
// Strings
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1 
Copy after login

5.define supports defining values ​​of array type

php 5.6 already supports CONST syntax to define constants of array classes, and PHP7 supports define syntax.

<&#63;php
define('ANIMALS', [
'dog',
'cat',
'bird'
]);
echo ANIMALS[1]; // outputs "cat" 
Copy after login

6. Anonymous class

<&#63;php
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;
$app->setLogger(new class implements Logger {
public function log(string $msg) {
echo $msg;
}
});
var_dump($app->getLogger()); 
Copy after login

7. Added the integer division function intdiv

Summary:

PHP 7’s performance breakthrough has become one of the hottest topics recently, and the official PHP 7.0.0 Beta 2 has been released

New Features

Performance improvement: PHP 7 is twice as fast as PHP 5.6

Full and consistent 64-bit support

Removed some old SAPI (Server Side Application Programming Port) and extensions that are no longer supported

New null join operator (??)

Articles you may be interested in:

  • Win2008 R2 IIS7 PHP 5.4 environment setup graphic tutorial
  • IIS7.5 PHP5.2.17 Mysql5.5.16 Zend3.3.3 under win2008 R2
  • Win7 scheduled task scheduled execution of PHP script settings diagram
  • Imagick and imagemagick extension tutorial for installing php under windows7
  • php-ssh2 extension tutorial for installing php under windows7
  • 3 solutions to the PHP error Allowed size memory of 67108864 bytes exhausted
  • IIS7, IIS7.5 Solutions to the slowdown of the site after upgrading to PHP5.3
  • IIS7 configuration PHP diagram ( IIS7 PHP_5.2.17/PHP_5.3.5)
  • win7 64-bit system configuration php latest version development environment (php Apache mysql)
  • Invisible character 65279 (utf-8 BOM header) problem in php
  • Connecting Oracle database with PHP under Win7 64-bit system
  • In-depth analysis of the new features of PHP7.0 (five major new features)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089589.htmlTechArticleI compiled the main new features of PHP 7.0. As of now, PHP has officially released The RC5 version of php7 is expected to release the first official version around November! Now...
Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!