PHP7 modified functions
- The scanner_mode parameter of parse_ini_file() and parse_ini_string() adds the INI_SCANNER_TYPED option.
- unserialize() adds a second parameter, which can be used to specify the list of accepted classes. RFC: https://wiki.php.net/rfc/secure_unserialize
- The maximum limit opened by proc_open() was previously hard-coded to 16. Now this limit has been removed. The maximum number depends on what PHP has available. Memory. The Windows version adds the option "blocking_pipes", which can be used to specify whether to force reading in blocks.
- array_column():The function now supports an array of objects as well as two-dimensional arrays
- stream_context_create()windows can receive array("pipe" => array("blocking " => <boolean>)) parameter.
- dirname() adds the option $levels, which can be used to specify the directory level. dirname(dirname($foo)) => dirname($foo, 2);
When debug_zval_dump() prints, use int instead of long and float instead of double.
PHP filter unserialize()
PHP 7 has added the ability to provide filtering for unserialize() Features can prevent code injection of illegal data and provide safer deserialized data.
Example
<?php class MyClass1 { public $obj1prop; } class MyClass2 { public $obj2prop; } $obj1 = new MyClass1(); $obj1->obj1prop = 1; $obj2 = new MyClass2(); $obj2->obj2prop = 2; $serializedObj1 = serialize($obj1); $serializedObj2 = serialize($obj2); // 默认行为是接收所有类 // 第二个参数可以忽略 // 如果 allowed_classes 设置为 false, unserialize 会将所有对象转换为 __PHP_Incomplete_Class 对象 $data = unserialize($serializedObj1 , ["allowed_classes" => true]); // 转换所有对象到 __PHP_Incomplete_Class 对象,除了 MyClass1 和 MyClass2 $data2 = unserialize($serializedObj2 , ["allowed_classes" => ["MyClass1", "MyClass2"]]); print($data->obj1prop); print(PHP_EOL); print($data2->obj2prop); ?>
The execution output of the above program is:
1 2