Introduction to new features of PHP7

Source: Internet
Author: User
Tags rfc
This article is based on the new files when PHP was released, link address: PHP 7 new

Features at a glance

    • Added?? operator
    • Added <=> Operato
      New operator
php//PHP 7: Compare the size of two numbers function Order_func ($a, $b) {    return ($a < $b)? 1: (($a > $b)? 1:0);} PHP new operator <=>,perfectfunction Order_func ($a, $b) {    return $a <=> $b;}
    • Added \u{xxxxx} Unicode codepoint Escape Syntax
      You can output Unicode characters directly using this method
Phpecho "\u{1f602}"; Outputs (this is the question mark inside the square brackets, because it is a Unicode character, the SG blog is not supported, published)
    • Added Error_clear_last () function
      A new function, the specific function did not delve into

    • Implemented the RFC Scalar Type decalarations v0.5. (Anthony)
      Variable type declaration (int, float, string, bool)
      A grammar associated with it: Declare (Strict_types=1);
      When Strict_types is set to 0,php, the function parameters and return values are strictly type judged
      Need the main is

      1 declare (Strict_types=1); Must be placed in the first line of the PHP file, this line cannot contain other content
      2 declare (Strict_types=1); Only affects internal files, files that contain this claim file do not affect
      3 Judging whether a function or method is strongly typed or weakly typed, look at the file that declares the function or method, at the beginning
      Whether there is a declare (Strict_types=1), there is this sentence, is the strong type
      Grammar Demo

php//declares that the function returns the type of the value and the parameter type function foobar (float $ABC): int {    return ceil ($ABC + 1);}
The type of the method parameter is declared here, and when called, if it is not the corresponding type, the type conversion is attempted first and then the converted value is passed in
    • mplemented the RFC Group use Declarations. (Marcio)
      This is nothing to say, PHP use introduced class more convenient neat
php//new grammar notation use foolibrary\bar\baz\{ClassA, ClassB, ClassC, CLASSD as Fizbo};//previous syntax notation use Foolibrary\bar\baz\classa;use Foolibrary\bar\baz\classb;use Foolibrary\bar\baz\classc;use FOOLIBRARY\BAR\BAZ\CLASSD as Fizbo;
    • Implemented the RFC Continue Output buffering. (Mike)
      Todo

    • Implemented the RFC Constructor behaviour of internal classes. (Dan, Dmitry)
      Todo

    • Implemented the RFC Fix "foreach" behavior. (Dmitry)
      Some boundaries of the foreach syntax are added for processing,
      Https://wiki.php.net/rfc/php7_foreach

    • Implemented the RFC Generator delegation. (BOB)
      Enhanced the functionality of the generator, which allows for many advanced features

php!--? php//usage, lightweight thread function g () {yield 1;  Yield from [2, 3, 4]; Yield 5;} $g = g (); foreach ($g as $yielded) {var_dump ($yielded);} /*int (1) int (2) int (3) int (4) int (5) */ 
  
  
  • Implemented the RFC Anonymous Class support. (Joe, Nikita, Dmitry)
    Anonymous class, this is not specifically described in

  • Implemented the RFC Context sensitive Lexer. (Marcio Almada)
    This feature is primarily a more user-friendly object-oriented nature of PHP
    in class properties or methods can use some keywords such as foreach,list,for

TODO

Sorry, a bit of a fever today, can't write down, will be free to continue

  • 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.