Some new features of PHP7 combine operators, combined with comparison operations, etc.

Source: Internet
Author: User
Tags php class

1. Combining Operators <=>

The spacehip operator returns 0 if the two operands are equal, 1, if the left is larger,-1, and the larger if appropriate. It is also known as the three-way comparison operator, which already exists in popular programming languages such as Perl and Ruby.

2, the empty merge operator and represents two question marks (?). )。 You can use it when you want to check if something is present and return a default value if it doesn't. The knot returns the result of its first operand if it exists and is not empty, and in any other case, the second operand.
Here's how long it takes for the new operator to reduce the basic claims:

3. Have you ever thought of declaring the return type of a function to prevent accidental return values? Then, the new PHP7 enables developers to improve their code quality with the help of return type declarations.

Describes a very simple use case where the Foo () function should return an array. See more complex examples here.

For enhanced functionality, PHP 7 introduces 4 new type-declaration scalar types: integer, float, String, and Boolean. The new scalar type allows the developer to indicate that they expect an integer, floating-point number, String, or Boolean value to be returned. The new scalar type introduced by PHP 7 also prompts the parameter type, allowing developers to enforce the type of the parameter because of the support of the PHP 5.X series.
5. Add Anonymous Class
PHP 7, you can use anonymous classes, one already in other object-oriented languages, such as C # and Java proven practices. Anonymous class is a class without a name. It instantiates an object that has the same functionality as the named Class object.
The syntax is the same as the traditional PHP class that we use, only the name is missing. If anonymous classes are used well, they can speed up coding and execution time. Anonymous class excellent When a class is executed and in case, when a class does not require a record to be used only once.

6. Easy to import the same namespace

The new group use claims feature will godsent those of you who want to import multiple classes from the same namespace. The new syntax cuts verbose, makes your code neat, easier on the eyes, and saves you a lot of typing time.

It will also be easier to read and debug the code, for groups to use the statement to help you determine the imports belonging to the same module.

Some new features of PHP7 combine operators, combined with comparison operations, etc.

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.