PHP7 New Content Summary (update at any time)

Source: Internet
Author: User

I. parameter and return value type declaration

It can be stated that: float,int,bool,string,interfaces,array,callable

General mode:

   function sum(int ...$ints) { return array_sum($ints); } print(sum(2, ‘3‘, 4.1)); //9
  Strict mode:  Declare (strict_types=   1); function sum  (int  ... $ints) {return array_sum ($ints); } print (SUM (2,  ' 3 ', 4.1)); //fatal error:uncaught typeerror:argument 2 passed to sum () must is of the type Integer, String giv En, ...              
   
return value:
Declare (strict_types = Span class= "Hljs-number" >1); function returnIntValue (int $value): int {return $value + 1.0; } print (Returnintvalue (5));
two.
Empty merge operator
  isset ($_get[ ' AA '])? $_get[< Span class= "hljs-string" > ' AA ']:  ' not passed ' equivalent to       $_get[ ' AA ']??:       Not passed '; 

three.
spaceship operator
   print (1 <=> 1)//0 print ( Span class= "Hljs-number" >1 <=> 2);//-1 print (2 <=> 1 );//1 

four. To define a solid array
  define (' animals 
Five.
Filter Unserialize
PHP 7 introduces a filtered unserialize () function to provide better security when deserializing objects on untrusted data. It prevents possible code injection and allows developers to whitelist classes that can be deserialized.

Six. Use batch declaration
under the same namespace, now you can batch declare
use some/namespace/{classa,  Classb, classc as c}; 

seven. Support for negative string offsets
var_dump("abcdef"[-2]);var_dump(strpos("aabbcc", "b", -3));

八.
foreach no longer changes the internal array pointer
$array = [0, 1, 2];foreach ($array as &$val) { var_dump(current($array));}

PHP5 output:
Int (1)
Int (2)
BOOL (FALSE)
PHP7 Output :
Int (0)
Int (0)
Int (0)



 
 

PHP7 New Content Summary (update at any time)

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.