Home>

Up to now,php has officially released the rc5 version of php7, and the first official version is expected to be released around November! Now, the important features of php7 are definitely stereotyped.No more changes.Subsequent versions of iterations are mainly bug fixes and optimizations.Let's talk about the new PHP7.0 features we have been waiting for.

Up to now,php has officially released the rc5 version of php7, and the first official version is expected to be released around November! Now, the important features of php7 are definitely stereotyped.No more changes.Subsequent versions of iterations are mainly bug fixes and optimizations.Let's talk about the new PHP7.0 features we have been waiting for.

1. Scalar parameter type declaration

String, integer (int), floating point (float), and bool parameter declarations are now supported.Previously only supported class names, interfaces, arrays and callables

Two styles:cast mode (default) and strict mode

<?php
//coercive mode
function sumofints (int ... $ints)
{
return array_sum ($ints);
}
var_dump (sumofints (2, "3", 4.1));

2. Return type declaration

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

3.?operator

??Used in place of the need for isset, 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

Just look at the size of the two expression values,Three relationships:= returns 0,<returns -1,>returns 1

<?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

5.define supports defining array type values

PHP 5.6 already supports const syntax to define array class constants,Define syntax is supported in php7.

<?php
define ("animals", [
"dog","cat","bird"
]);
echo animals [1];//outputs "cat"

6. Anonymous Class

<?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 ());

7.Added intdiv function

summary:

PHP 7 ’s breakthrough in performance has become one of the hottest topics recently.Currently 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 not supported

Added null join operator (??)

php
  • Previous PHP uses trim function to remove left and right strings and special characters
  • Next Detailed installation and configuration of SVNServer under Windows