In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the advantages of the PHP7.0 version". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the advantages of the PHP7.0 version"?
1. Backward incompatible changes
Language change
Changes in variable processing
Indirect variables, properties, and method references are now interpreted in semantics from left to right. Some examples:
$foo ['bar'] [' baz'] / / explain to do ($$foo) ['bar'] [' baz'] $foo- > $bar ['baz'] / / explain to do ($foo- > $bar) [' baz'] $foo- > $bar ['baz'] () / explain to do ($foo- > $bar) [' baz'] () Foo::$bar ['baz'] () / / explain to do (Foo::$bar) [' baz'] ()
To restore previous behavior, you need to explicitly enlarge the parentheses:
${$foo ['bar'] [' baz']} $foo- > {$bar ['baz']} $foo- > {$bar [' baz']} () Foo:: {$bar ['baz']} ()
Global keywords now accept only simple variables. Like the old ones.
The copy code is as follows:
Global $$foo- > bar
Now it is required to be written as follows:
The copy code is as follows:
Global ${$foo- > bar}
Parentheses before and after a variable or function call no longer have any effect. For example, in the following code, the result of a function call is passed to a function by reference
Function getArray () {return [1,2,3];} $last = array_pop (getArray ()); / / Strict Standards: only variables can pass $last = array_pop ((getArray () by reference.
/ / Strict Standards: only variables can be passed by reference
Now a strict standard error is thrown regardless of whether you use parentheses or not. Previously, there was no prompt in the second invocation mode.
Array elements or object properties are automatically installed and the reference order is created, and the result order will now be different. For example:
$array = []; $array ["a"] = & $array ["b"]; $array ["b"] = 1 [array]; now the result is ["a" = > 1, "b" = > 1], whereas the previous result is ["b" = > 1, "a" = > 1]
Related RFC:
Https://wiki.php.net/rfc/uniform_variable_syntax
Https://wiki.php.net/rfc/abstract_syntax_tree
Changes in list ()
List () is no longer assigned in reverse order, for example:
The copy code is as follows:
List ($array [], $array [], $array []) = [1,2,3]
Var_dump ($array)
Now the result is $array = [1, 2, 3], not [3, 2, 1]. Note that only the order of assignment has changed, but the assignment remains the same (LCTT), that is, the previous list () behavior starts from the following variables one by one, so that the above usage will produce such a result. ). For example, general usage similar to the following
The copy code is as follows:
List ($a, $b, $c) = [1,2,3]
/ / $a = 1; $b = 2; $c = 3
Still maintain the current behavior.
Empty list () assignments are no longer allowed. The following are all invalid:
List () = $a * list (,) = $a * list ($x, list (), $y) = $a *
The code is as follows:
The copy code is as follows:
$string = "xy"
List ($x, $y) = $string
The result now is: $x = = null and $y = = null (no prompt), while the previous results are: $x = "x" and $y = = "y".
In addition, list () can now always handle objects that implement ArrayAccess, such as:
The copy code is as follows:
List ($a, $b) = (object) new ArrayObject ([0,1])
The result now is: $a = = 0 and $b = = 1. Previously, both $an and $b were null.
Related RFC:
Https://wiki.php.net/rfc/abstract_syntax_tree#changes_to_list
Https://wiki.php.net/rfc/fix_list_behavior_inconsistency
Changes in foreach
The foreach () iteration no longer affects the internal pointers of the array, which can be accessed through a series of functions such as current () / next (). For example:
The copy code is as follows:
$array = [0,1,2]
Foreach ($array as & $val) {
Var_dump (current ($array))
}
Now point to the value int (0) three times. The previous output was int (1), int (2), and bool (false).
When iterating over an array by value, foreach is always operating on a copy of the array, and any operation on the array during the iteration will not affect the iterative behavior. For example:
The copy code is as follows:
$array = [0,1,2]
$ref = & $array; / / Necessary to trigger the old behavior
Foreach ($array as $val) {
Var_dump ($val)
Unset ($array [1])
}
All three elements (0 1 2) will now be printed out, while the previous second element 1 will be skipped (0 2).
When iterating over an array by reference, modifications to the array will continue to affect the iteration. Now, however, PHP can better maintain positions in the array when using numbers as keys. For example, add array elements during iteration by reference:
The copy code is as follows:
$array = [0]
Foreach ($array as & $val) {
Var_dump ($val)
$array [1] = 1
}
Now the iteration will add the elements correctly. As shown above, the code output is "int (0) int (1)", whereas it was just "int (0)" before.
Iterating over ordinary (non-traverable) objects by value or by reference is similar to iterating by reference on an array. This is in line with previous behavior, except for the more accurate location management improvements described above.
The iterative behavior of traverable objects remains the same.
Related RFC: https://wiki.php.net/rfc/php7_foreach
Changes in parameter processing
You cannot define two function parameters with the same name. For example, the following method will trigger a compile-time error:
The copy code is as follows:
Public function foo ($a, $b, $unused, $unused) {
/ /...
}
The code above should be modified to use different parameter names, such as:
The copy code is as follows
Public function foo ($a, $b, $unused1, $unused2) {
/ /...
}
The func_get_arg () and func_get_args () functions no longer return the original value passed to the parameter, but instead return their current value (which may be modified). For example:
The copy code is as follows:
Function foo ($x) {
$xbirthday +
Var_dump (func_get_arg (0))
}
Foo (1)
"2" instead of "1" will be printed. The code should be changed to modify only after the call to func_get_arg (s).
The copy code is as follows:
Function foo ($x) {
Var_dump (func_get_arg (0))
$xbirthday +
}
Or you should avoid modifying parameters:
The copy code is as follows:
Function foo ($x) {
$newX = $x + 1
Var_dump (func_get_arg (0))
}
Similarly, exception backtracking no longer displays the original value passed to the function, but the modified value. For example:
The copy code is as follows:
Function foo ($x) {
$x = 42
Throw new Exception
}
Foo ("string")
Now the result of the stack trace is:
The copy code is as follows:
Stack trace:
# 0 file.php (4): foo (42)
# 1 {main}
It used to be:
The copy code is as follows:
Stack trace:
# 0 file.php (4): foo ('string')
# 1 {main}
This does not affect the runtime behavior of your code, but it is worth noting that it will be different when debugging.
The same limitation affects debug_backtrace () and other functions that check function parameters.
Related RFC: https://wiki.php.net/phpng
Changes in integer processing
Invalid octal representations (containing numbers greater than 7) now produce compilation errors. For example, the following code is no longer valid:
$I = 0781; / 8 is not a valid octal number!
Previously, invalid numbers (and any numbers after invalid numbers) were simply ignored. Previously, the value of $I was 7, because the last two digits were quietly discarded.
Binary mirroring displacements with negative numbers now throws an arithmetic error:
The copy code is as follows:
Var_dump (1 >-1)
/ / ArithmeticError: displacement with negative number
When the number of bits shifted to the left exceeds the integer width, the result is always 0.
The copy code is as follows:
Var_dump (1 > 64); / / int (0)
Var_dump (- 1 > > 64); / / int (- 1)
Related RFC: https://wiki.php.net/rfc/integer_semantics
Changes in string processing
Strings that contain hexadecimal numbers are no longer treated as numbers and are not specially treated. See the new behavior in the example:
The copy code is as follows:
Var_dump ("0x123" = "291"); / / bool (false) (formerly true)
Var_dump (is_numeric ("0x123")); / / bool (false) (formerly true)
Var_dump ("0xe" + "0x1"); / / int (0) (previously 16)
Var_dump (substr ("foo", "0x1")); / / string (3) "foo" (formerly "oo")
/ / Note: an abnormally formatted number was encountered
Filter_var () can be used to check whether a string contains hexadecimal numbers, or whether the string can be converted to an integer:
$str = "0xffff"; $int = filter_var ($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX); if (false = $int) {throw new Exception ("Invalid integer!");} var_dump ($int); / / int (65535)
Due to the addition of Unicode code point escape format (Unicode Codepoint Escape Syntax) to double quote strings and HERE documents, "\ u {" with invalid sequences will now cause an error:
$str = "\ u {xyz}"; / / fatal error: invalid UTF-8 code point escape sequence
To avoid this, you need to escape the starting backslash:
$str = "\\ u {xyz}"; / / correct
However, not following {"u" is not affected. The following code does not generate errors and works as before:
$str = "\ u202e"; / / correct
Related RFC:
Https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings
Https://wiki.php.net/rfc/unicode_escape
Changes in error handling
There are now two exception classes: Exception and Error. Both classes implement a new interface: Throwable. The type in the exception handling code indicates that it may need to be modified to handle this situation.
Some fatal errors and recoverable fatal errors are now thrown an Error. Because Error is a class independent of Exception, these exceptions are not caught by existing try/catch blocks.
Recoverable fatal errors are converted to an exception, so they cannot be quietly ignored in error handling. In some cases, the type indicates that failure can no longer be ignored.
The parsing error now generates a ParseError for the Error extension. In addition to the previous processing based on the return value / errorgetlast (), the error handling of eval () for some code that may not be valid should be changed to capture ParseError.
The constructor of the inner class always throws an exception when it fails. Previously, some constructors returned NULL or an object that was not available.
The error level of some E_STRICT prompts has changed.
Related RFC:
Https://wiki.php.net/rfc/engine_exceptions_for_php7
Https://wiki.php.net/rfc/throwable-interface
Https://wiki.php.net/rfc/internal_constructor_behaviour
Https://wiki.php.net/rfc/reclassify_e_strict
Other language changes
Static invocation of a non-static call to an incompatible $this context is no longer supported. In this case, $this is undefined, but calls to it are allowed with an obsolete prompt. Example:
Class A {public function test () {var_dump ($this);} / Note: class B {public function callNonStaticMethodOfA () {A::test ();}} (new B)-> callNonStaticMethodOfA () is not extended from class A.
/ / obsolete: the non-static method A::test () should not be called statically
/ / hint: undefined variable $this
NULL
Note that this occurs only on calls from incompatible contexts. If class B extends from class A, the call is allowed without any hint.
The following class names, interface names, and special names (case sensitive) cannot be used:
Bool
Int
Float
String
Null
False
True
This is used in class/interface/trait declarations, class_alias (), and use statements.
In addition, the following class names, interface names, and special names are reserved for future use, but using fashion does not throw an error:
Resource
Object
Mixed
Numeric
Yield statement structure when used in an expression context, parentheses are no longer required. It is now a right associative operator with priority between "print" and "= >". In some cases, this can lead to different behaviors, such as:
Echo yield-1
/ / previously explained as follows
Echo (yield)-1
/ / it is now explained as follows
Echo yield (- 1)
Yield $foo or die
/ / previously explained as follows
Yield ($foo or die)
/ / it is now explained as follows
(yield $foo) or die
This situation can be solved by adding parentheses.
Removing ASP ('private'] sets the session.cache_limiter=private. Read_and_close' is also supported to close session data as soon as the data is read.
The session saving processor accepts the use of validate_sid () and update_timestamp () to verify the existence of the session ID and update the session timestamp. Continue to be compatible with older user-defined session save handlers.
Added SessionUpdateTimestampHandlerInterface. ValidateSid () and updateTimestamp () are defined in the interface.
The INI setting for session.lazy_write (default is On) supports writing only when session data is updated.
Opcache
Remove the opcache.load_comments configuration statement. Comments in the file are now loaded at no cost and are always enabled.
OpenSSL:
Remove the "rsa_key_size" SSL context option and automatically set the appropriate size according to the given negotiated encryption algorithm.
Remove the "CN_match" and "SNI_server_name" SSL context options. Use automatic detection or the "peer_name" option instead.
PCRE:
Remove support for the / e (PREG_REPLACE_EVAL) modifier and use preg_replace_callback () instead.
PDO_pgsql:
Remove the PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT attribute, which is equivalent to ATTR_EMULATE_PREPARES.
Standard:
Remove string catalog support from setlocale (). Use the LC_* constant instead. Instead.
Remove set_magic_quotes_runtime () and its alias magic_quotes_runtime ().
JSON:
Reject RFC 7159 incompatible number formats in json_decode-top level (07, 0xff, .1,-.1) and all layers ([1.], [1.e1])
Calling json_decode with one parameter is equivalent to calling with an empty PHP string or value, and the result of converting to an empty string (NULL, FALSE) is a JSON format error.
Stream:
Remove set_socket_blocking (), which is equivalent to its alias stream_set_blocking ().
XSL:
Remove the xsl.security_prefs ini option and use XsltProcessor::setSecurityPrefs () instead.
two。 New function
Core
Group use declaration has been added. (RFC: https://wiki.php.net/rfc/group_use_declarations)
The null merge operator has been added. (RFC: https://wiki.php.net/rfc/isset_ternary)
Strings of length > = 231 bytes are supported on 64-bit architectures.
Added the Closure::call () method (classes that only work on the user side).
The\ u {xxxxxx} Unicode code point escape format has been added to the double quote string and the here document.
Define () now supports arrays as constant values, fixing an omission when define () does not support array constant values.
The comparison operator (), the spacecraft operator, has been added. (RFC: https://wiki.php.net/rfc/combined-comparison-operator)
A yield from operator similar to a collaborator has been added to the delegate generator. (RFC: https://wiki.php.net/rfc/generator-delegation)
Reserved keywords can now be used in several new contexts. (RFC: https://wiki.php.net/rfc/context_sensitive_lexer)
Added declaration support for scalar types, and can use the declaration strict mode of declare (strict_types=1). (RFC: https://wiki.php.net/rfc/scalar_type_hints_v5)
Added support for random number generators on the user side of encryption-level security. (RFC: https://wiki.php.net/rfc/easy_userland_csprng)
Opcache
Added file-based secondary opcode caching (experimental-disabled by default). To enable it, PHP needs to be configured and built using-- enable-opcache-file, and then the opcache.file_cache= configuration instruction can be set in php.ini. Secondary caching may improve performance when the server is restarted or SHM is reset. Alternatively, opcache.file_cache_only=1 can be set to use file caching without SHM at all (which may be useful for shared hosts), and opcache.file_cache_consistency_checks=0 can be set to disable file cache consistency checking to speed up the loading process, which is a security risk.
OpenSSL
When building with OpenSSL 1.0.2 and update, the "alpn_protocols" SSL context option has been added to allow encrypted client / server streams to use ALPN TLS extensions to negotiate alternative protocols. The negotiated protocol information can be accessed through the stream_get_meta_data () output.
Reflection
A ReflectionGenerator class (yield from Traces, current file / line, etc.) has been added.
A ReflectionType class has been added to better support the new return type and scalar type declaration capabilities. The new ReflectionParameter::getType () and ReflectionFunctionAbstract::getReturnType () methods both return an instance of ReflectionType.
Stream
Added a new stream context option for Windows only to allow blocking pipeline reads. To enable this feature, pass array ("pipe" = > array ("blocking" = > true) when the flow context is created. It is important to note that this option causes a deadlock in the pipe buffer, but it is useful in several command line scenarios.
3. Changes in SAPI module
FPM
Fix error # 65933 (configuration lines that cannot be set to exceed 1024 bytes).
Listen = port is now listening on all addresses (IPv6 and IPv4 mapped).
4. Discarded function
Core
Obsolete PHP 4-style builders (that is, the builder must have the same name as the class name).
Static calls to non-static methods are discarded.
OpenSSL
The "capture_session_meta" SSL context option has been discarded. Encryption-related metadata active on the stream resource can be accessed through the return value of stream_get_meta_data ().
5. The change of function
Parse_ini_file ():
Parse_ini_string ():
Added scan mode INISCANNERTYPED to get the .ini value of type yield.
Unserialize ():
Added a second parameter to the unserialize function (RFC: https://wiki.php.net/rfc/secure_unserialize) to specify the acceptable class: unserialize ($foo, ["allowed_classes" = > ["MyClass", "MyClass2"]])
Proc_open ():
The maximum number of pipes that can be used by proc_open () was previously hard-coded to 16. Now this limitation has been removed and is only limited by the amount of memory available in PHP.
The newly added Windows-only configuration option "blocking_pipes" can be used to force blocking of reads to child process pipes. This can be used in several command-line application scenarios, but it can lead to deadlocks. In addition, this is related to the pipeline context option for the new stream.
Array_column ():
This function now supports an array of objects as a two-dimensional array. Only public properties will be processed, and dynamic properties that use _ _ get () in the object must also implement _ _ isset ().
Stream_context_create ()
You can now accept a configuration array ("pipe" = > array ("blocking" = >) that is only available to Windows to force blocking pipe reads. This option should be used with care, as the platform may cause a deadlock in the pipe buffer.
6. New function
GMP
Gmp_random_seed () has been added.
PCRE:
The preg_replace_callback_array function was added. (RFC: https://wiki.php.net/rfc/preg_replace_callback_array)
Standard. The integer division intdiv () function has been added. . Added the error_clear_last () function to reset the error state.
Zlib:. Deflate_init (), deflate_add (), inflate_init (), inflate_add () functions have been added to run increment and stream compression / decompression.
7. New classes and interfaces
(not yet)
8. Removed extensions and SAPI
Sapi/aolserver
Sapi/apache
Sapi/apache_hooks
Sapi/apache2filter
Sapi/caudium
Sapi/continuity
Sapi/isapi
Sapi/milter
Sapi/nsapi
Sapi/phttpd
Sapi/pi3web
Sapi/roxen
Sapi/thttpd
Sapi/tux
Sapi/webjames
Ext/mssql
Ext/mysql
Ext/sybase_ct
Ext/ereg
For more details, see:
Https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts
Https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7
Note: NSAPI does not vote in RFC, but it will be removed later. That is to say, its related SDK will not be available in the future.
9. Other changes to the expansion
Mhash
Mhash is not an extension in the future. Use function_exists ("mhash") to check if the device is available.
10. New global constant
Core. Add PHP_INT_MIN
Zlib
These constants are added to control the refresh behavior of the new incremental deflate_add () and inflate_add () functions:
ZLIB_NO_FLUSH
ZLIB_PARTIAL_FLUSH
ZLIB_SYNC_FLUSH
ZLIB_FULL_FLUSH
ZLIB_BLOCK
ZLIB_FINISH
GD
Remove T1Lib support so that due to optional dependencies on T1Lib, the following will not be available in the future:
Function:
Imagepsbbox ()
Imagepsencodefont ()
Imagepsextendedfont ()
Imagepsfreefont ()
Imagepsloadfont ()
Imagepsslantfont ()
Imagepstext ()
Resources:
'gd PS font'
'gd PS encoding'
11. Changes in INI file processing
Core
Remove the asp_tags ini directive. Enabling it will result in a fatal error.
Remove the always_populate_raw_post_data ini directive.
12. Windows support
Core
Native 64-bit integers are supported on 64-bit systems.
Large files are supported on 64-bit systems.
Getrusage () is supported.
Ftp
The ftp extensions that come with are always shared libraries.
For SSL support, remove the dependency on openssl extensions and instead rely only on the openssl library. Ftp_ssl_connect () is automatically enabled if needed at compile time.
Odbc
The odbc extensions that come with are always shared libraries.
13. Other changes
Core
NaN and Infinity are always 0 when converted to integers, not undefined platform-related ones.
Calling a method on a non-object triggers a trappable error, not a fatal error; see: https://wiki.php.net/rfc/catchable-call-to-member-of-non-object
Zend_parse_parameters, type hints, and conversions, now always use "integer" and "float" instead of "long" and "double".
If ignore_user_abort is set to true, the output cache will continue to work corresponding to the broken connection.
Thank you for your reading, the above is the content of "what are the advantages of the PHP7.0 version?" after the study of this article, I believe you have a deeper understanding of the advantages of the PHP7.0 version, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.