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 new features of PHP5.5

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail what the new features of PHP5.5 are, and the editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1 Generator yield keyword

The Chinese document of yield is here: http://php.net/manual/zh/language.generators.overview.php

If you look at the documentation, you can see that one of the functions of yield is that it can effectively reduce the memory overhead of iterations. For example, the xrange example on the official website:

The code is as follows:

Xrange here is an iteration, and the function is the same as range. If you use the range function, then the internal implementation of the function will store the intermediate process of each iteration, that is, each intermediate variable has a memory space, then the memory space used by the program is larger in the first place, and allocating memory and recycling memory will lead to longer running time of the program. But if you use the xrange function implemented on yield, all the intermediate variables in it use only one memory $I, which saves less time and space.

So why does yield have this effect? Think of yield in lua, this is the concept of collaborative process. In the Lua language, when the program runs to yield, the context is recorded by the co-program, and then the operation right of the program is returned to the main function. When the main function calls resume, the co-program is recalled and the context of the yield record is read. This forms the multi-program operation at the program language level. The same is true for yield in php 5.5. when the program runs to yield, the current program evokes the co-program logging context, and then the main function continues to operate, except that the php does not use keywords such as resume, but "call" the co-program when it is in use. For example, the foreach iterator in the above example can evoke yield. So the above example is understandable.

In fact, according to the reference yield, many internal functions, especially those related to iterations, should be possible to optimize. Maybe there will be yield versions and non-yield versions of functions that implement the same function.

2 finally keyword

This is the same as the finally in java, the classic try. Catch... Finally three-stage exception handling.

3 foreach supports list ()

To iterate over an array of arrays, you used to use two foreach, now you only need to use foreach + list, but the number of each array in the array of this array needs to be the same. The example of looking at the document can be understood at a glance.

The copy code is as follows:

4 empty () supports custom functions

Previously, parameters in empty () could not be functions. It's okay now.

The copy code is as follows:

6 class names can be obtained through:: class

The copy code is as follows:

7 added opcache extension

Using opcache will improve the performance of php, and you can add this optimization to static compilation (--enable-opcache) or dynamic extension (zend_extension) like other extensions.

This is the end of the article on "what are the new features of PHP5.5". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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