Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common new features of PHP7

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about what PHP7 commonly used new features are, the editor thinks it is very practical, so share it with you to learn, hope you can get something after reading this article, say no more, follow the editor to have a look.

1.PHP scalar type and return value type declaration

PHP 7 adds the feature of scalar type declaration, which has two modes:

Force mode (default)

Strict mode

2.PHP NULL merge operator

The new NULL merge operator added in PHP 7 is a shortcut to perform ternary operations for isset () detection.

The NULL merge operator determines whether the variable exists and the value is not NULL. If so, it returns its own value, otherwise it returns its second Operand.

For example: $a? $a: 0; change to $a? 0

3.PHP space ship operator (combinatorial comparator)

The new spaceship operator (combination comparator) in PHP 7 is used to compare two expressions $an and $b, which returns-1, 0, or 1, respectively, if $an is less than, equal to, or greater than $b.

For example:

Print (1 1); print (PHP_EOL); result 0print (1 2); print (PHP_EOL); result-1print (21); print (PHP_EOL); result 1print (PHP_EOL); / / PHP_EOL is a newline character

4.PHP constant array

In PHP 5.6, constant arrays can only be defined by const, and PHP 7 can be defined by define ().

For example: define ('sites', [' Google','Runoob','Taobao'])

5. Anonymous class

PHP 7 supports the instantiation of an anonymous class through new class, which can be used to replace some complete class definitions of "burning after use".

6.PHP filter unserialize ()

PHP 7 adds features that provide filtering for unserialize (), preventing code injection of illegal data, and providing more secure deserialization of data.

7.PHP 7 use statement

PHP 7 can use one use to import classes, functions, and constants from the same namespace

8.PHP 7 error handling

PHP 7 changes the way most errors are reported. Unlike PHP 5's traditional error reporting mechanism, most errors are now thrown as Error exceptions.

This Error exception can be caught by a try / catch block like a normal exception. If there is no matching try / catch block, the exception handler (registered by set_exception_handler ()) is called to handle it. If the exception handler has not been registered, it is handled the traditional way: it is reported as a fatal error (Fatal Error).

The Error class does not extend from the Exception class, so you cannot capture Error with code like catch (Exception $e) {...}. You can use PHP source code like catch (Error $e) {...}, or you can capture Error by registering the exception handler (set_exception_handler ()).

9.PHP 7 Session option

The PHP 7 session_start () function can take an array as an argument, overriding the configuration item of session in php.ini.

This feature also introduces a new php.ini setting (session.lazy_write), which is set to true by default, meaning that session data is written only when it changes.

In addition to the regular session configuration instructions, you can also include the read_and_close option in this array. If the value of this option is set to TRUE, the session file will be closed immediately after reading, so unnecessary file locks can be avoided when the session data has not changed.

Extensions removed by 10.PHP 7

The PHP 7 + version removes the following extension: ereg,mssql,mysql,sybase_ct.

These are the common new features of PHP7, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report