PHP5.4的变化关注---What has changed in PHP 5.4.x(转)
What has changed in PHP 5.4.x
Most improvements in PHP 5.4.x have no impact on existing code. There are a few incompatibilities and new features that should be considered, and code should be tested before switching PHP versions in production environments.
1. Backward Incompatible Changes :一些内容将不兼容
7) 注意非数字数组键值 详看:PHP5.4中一个需要注意的变化(Chained string offsets)
8) 数组转字符串提示 E_NOTICE
level error
- function foo($_GET, $_POST) {}
- //在5.3是没问题的.
- //php5.4出现:Fatal error: Cannot re-assign auto-global variable _GET in /opt/php-5.4.0/test.php on line 4
Although most existing PHP 5 code should work without changes, please take note of some backward incompatible changes:
- Safe mode is no longer supported. Any applications that rely on safe mode may need adjustment, in terms of security.
- Magic quotes has been removed. Applications relying on this feature may need to be updated, to avoid security issues. get_magic_quotes_gpc() and get_magic_quotes_runtime() now always return
FALSE
.set_magic_quotes_runtime() raises anE_CORE_ERROR
level error. - The register_globals and register_long_arrays php.ini directives have been removed.
- Call-time pass by reference has been removed.
- The break and continue statements no longer accept variable arguments (e.g., break 1 + foo() * $bar;). Static arguments still work, such as break 2;.
- In the date and time extension, the timezone can no longer be set using the TZ environment variable. Instead you have to specify a timezone using the date.timezone php.ini option or date_default_timezone_set() function. PHP will no longer attempt to guess the timezone, and will instead fall back to "UTC" and issue a
E_WARNING
. - Non-numeric string offsets - e.g. $a['foo'] where $a is a string - now return false on isset() and true on empty(), and produce a
E_WARNING
if you try to use them. Offsets of types double, bool and null produce aE_NOTICE
. Numeric strings (e.g. $a['2']) still work as before. Note that offsets like '12.3' and '5 foobar' are considered non-numeric and produce aE_WARNING
, but are converted to 12 and 5 respectively, for backward compatibility reasons. Note: Following code returns different result. $str='abc';var_dump(isset($str['x'])); // false for PHP 5.4 or later, but true for 5.3 or less - Converting an array to a string will now generate an
E_NOTICE
level error, but the result of the cast will still be the string "Array". - Turning
NULL
,FALSE
, or an empty string into an object by adding a property will now emit anE_WARNING
level error, instead ofE_STRICT
. - Parameter names that shadow super globals now cause a fatal error. This prohibits code like function foo($_GET, $_POST) {}.
- The Salsa10 and Salsa20 hash algorithms have been removed.
- array_combine() now returns array() instead of
FALSE
when two empty arrays are provided as parameters. - If you use htmlentities() with asian character sets, it works like htmlspecialchars() - this has always been the case in previous versions of PHP, but now an
E_STRICT
level error is emitted.
The following keywords are now reserved, and may not be used as names by functions, classes, etc.
The following functions have been removed from PHP:
- define_syslog_variables()
- import_request_variables()
- session_is_registered(), session_register() and session_unregister().
- The aliases mysqli_bind_param(), mysqli_bind_result(), mysqli_client_encoding(), mysqli_fetch(), mysqli_param_count(), mysqli_get_metadata(), mysqli_send_long_data(), mysqli::client_encoding() and mysqli_stmt::stmt().
2. New features 新功能
- $bin = 0b1101;
- echo $bin;
- //13
PHP 5.4.0 offers a wide range of new features:
- Support for traits has been added.
- Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];.
- Function array dereferencing has been added, e.g. foo()[0].
- Closures now support $this.
- <?= is now always available, regardless of the short_open_tag php.ini option.
- Class member access on instantiation has been added, e.g. (new Foo)->bar().
- Class::{expr}() syntax is now supported.
- Binary number format has been added, e.g. 0b001001101.
- Improved parse error messages and improved incompatible arguments warnings.
- The session extension can now track the upload progress of files.
- Built-in development web server in CLI mode.
Changes in SAPI modules
- A new SAPI module named cli-server is now available.
- Added CLI option --rz which shows information of the named Zend extension.
- Added shortcut #inisetting=value to change php.ini settings at run-time in interactive readline CLI
- Added apache compatible functions: apache_child_terminate(), getallheaders(), apache_request_headers() and apache_response_headers() for FastCGI SAPI.
- PHP-FPM: Added the process.max setting, to control the number of processes that FPM can fork.
3 . Deprecated features in PHP 5.4.x 弃用的功能
Deprecated functions:
4. Changed Functions 变化的自带函数
Several functions were given new, optional parameters in PHP 5.4:
PHP Core:
- Added the optional
limit
parameter to debug_backtrace() and debug_print_backtrace(), to limit the amount of stack frames returned. - is_link() now works properly for symbolic links on Windows Vista or later. Earlier systems do not support symbolic links.
OpenSSL:
- Added a no padding option to the openssl_encrypt() and openssl_decrypt() functions.
Intl:
- idn_to_ascii() and idn_to_utf8() now take two extra parameters, one indicating the variant (IDNA 2003 or UTS #46) and another, passed by reference, to return details about the operation in case UTS #46 is chosen.
5. New Functions 新增的函数
HP 5.4 introduced some new functions:
PHP Core:
- hex2bin()
- http_response_code()
- get_declared_traits()
- getimagesizefromstring()
- stream_set_chunk_size()
- socket_import_stream()
- trait_exists()
- header_register_callback()
- transliterator_create()
- transliterator_create_from_rules()
- transliterator_create_inverse()
- transliterator_get_error_code()
- transliterator_get_error_message()
- transliterator_list_ids()
- transliterator_transliterate()
6 . New Classes and Interfaces 新增的类和接口
The following classes were introduced in PHP 5.4.0:
SPL:
Json:
Snmp:
Intl:
7. New Methods 新增的方法
Several new methods were introduced in 5.4.0:
XSL:
SPL:
- RegexIterator::getRegex()
- SplObjectStorage::getHash()
- DirectoryIterator::getExtension()
- SplDoublyLinkedList::serialize()
- SplDoublyLinkedList::unserialize()
- SplFileInfo::getExtension()
- SplFileObject::fputcsv()
- SplQueue::serialize()
- SplQueue::unserialize()
- SplStack::serialize()
- SplStack::unserialize()
- SplTempFileObject::fputcsv()
- ReflectionExtension::isPersistent()
- ReflectionExtension::isTemporary()
- ReflectionClass::isCloneable()
- PDO::newRowset()
8. Removed Extensions 移除扩展sqlite
These extensions have been moved to PECL and are no longer part of the PHP distribution. The PECL package versions of these extensions will be created according to user demand.
- sqlite - Note that ext/sqlite3 and ext/pdo_sqlite are not affected
9 .Other changes to extensions 修改的扩展
Changes in extension behavior, and new features:
- mysqli - mysqli_result now implements Traversable
- pdo_mysql - Removed support for linking with MySQL client libraries older than 4.1
- The MySQL extensions mysql, mysqli and PDO_mysql use mysqlnd as the default library now. It is still possible to use libmysql by specifying a path to the configure options.
- mysqlnd - Added named pipes support
10. New Global Constants 新增的全局常量
PHP Core:
ENT_DISALLOWED
ENT_HTML401
ENT_HTML5
ENT_SUBSTITUTE
ENT_XML1
ENT_XHTML
IPPROTO_IP
IPPROTO_IPV6
IPV6_MULTICAST_HOPS
IPV6_MULTICAST_IF
IPV6_MULTICAST_LOOP
IP_MULTICAST_IF
IP_MULTICAST_LOOP
IP_MULTICAST_TTL
MCAST_JOIN_GROUP
MCAST_LEAVE_GROUP
MCAST_BLOCK_SOURCE
MCAST_UNBLOCK_SOURCE
MCAST_JOIN_SOURCE_GROUP
MCAST_LEAVE_SOURCE_GROUP
Curl:
CURLOPT_MAX_RECV_SPEED_LARGE
CURLOPT_MAX_SEND_SPEED_LARGE
LIBXML_HTML_NODEFDTD
LIBXML_HTML_NOIMPLIED
LIBXML_PEDANTIC
OPENSSL_CIPHER_AES_128_CBC
OPENSSL_CIPHER_AES_192_CBC
OPENSSL_CIPHER_AES_256_CBC
OPENSSL_RAW_DATA
OPENSSL_ZERO_PADDING
PHP_OUTPUT_HANDLER_CLEAN
PHP_OUTPUT_HANDLER_CLEANABLE
PHP_OUTPUT_HANDLER_DISABLED
PHP_OUTPUT_HANDLER_FINAL
PHP_OUTPUT_HANDLER_FLUSH
PHP_OUTPUT_HANDLER_FLUSHABLE
PHP_OUTPUT_HANDLER_REMOVABLE
PHP_OUTPUT_HANDLER_STARTED
PHP_OUTPUT_HANDLER_STDFLAGS
PHP_OUTPUT_HANDLER_WRITE
PHP_SESSION_ACTIVE
PHP_SESSION_DISABLED
PHP_SESSION_NONE
STREAM_META_ACCESS
STREAM_META_GROUP
STREAM_META_GROUP_NAME
STREAM_META_OWNER
STREAM_META_OWNER_NAME
STREAM_META_TOUCH
Zlib:
ZLIB_ENCODING_DEFLATE
ZLIB_ENCODING_GZIP
ZLIB_ENCODING_RAW
Intl:
U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
IDNA_CHECK_BIDI
IDNA_CHECK_CONTEXTJ
IDNA_NONTRANSITIONAL_TO_ASCII
IDNA_NONTRANSITIONAL_TO_UNICODE
INTL_IDNA_VARIANT_2003
INTL_IDNA_VARIANT_UTS46
IDNA_ERROR_EMPTY_LABEL
IDNA_ERROR_LABEL_TOO_LONG
IDNA_ERROR_DOMAIN_NAME_TOO_LONG
IDNA_ERROR_LEADING_HYPHEN
IDNA_ERROR_TRAILING_HYPHEN
IDNA_ERROR_HYPHEN_3_4
IDNA_ERROR_LEADING_COMBINING_MARK
IDNA_ERROR_DISALLOWED
IDNA_ERROR_PUNYCODE
IDNA_ERROR_LABEL_HAS_DOT
IDNA_ERROR_INVALID_ACE_LABEL
IDNA_ERROR_BIDI
IDNA_ERROR_CONTEXTJ
Json:
JSON_PRETTY_PRINT
JSON_UNESCAPED_SLASHES
JSON_NUMERIC_CHECK
JSON_UNESCAPED_UNICODE
JSON_BIGINT_AS_STRING
11. Changes to INI file handling php.ini的设置变化
he following php.ini directives have been removed:
- register_globals and register_long_arrays
- magic_quotes_gpc, magic_quotes_runtime, and magic_quotes_sybase
- allow_call_time_pass_reference
- define_syslog_variables
- highlight.bg
- session.bug_compat_42 and session.bug_compat_warn
- y2k_compliance
- safe_mode, safe_mode_gid, safe_mode_include_dir, safe_mode_exec_dir, safe_mode_allowed_env_vars, and safe_mode_protected_env_vars
The following php.ini directives have been added:
- cli.pager and cli.prompt for CLI SAPI using readline in interactive mode.
- cli_server.color to enable the built-in development web server to use ANSI color coding in terminal output.
- max_input_vars - specifies how many GET/POST/COOKIE input variables may be accepted.
- zend.multibyte - to control the new multibyte support.
- zend.script_encoding - This value will be used unless a "declare(encoding=...)" directive appears at the top of the script.
- zend.signal_check - to check for replaced signal handlers on shutdown.
- session.upload_progress.enabled, session.upload_progress.cleanup, session.upload_progress.prefix, session.upload_progress.name, session.upload_progress.freq, session.upload_progress.min_freq
- enable_post_data_reading - When it's disabled, the POST data is not read (and processed)
- windows_show_crt_warning - This directive shows the Windows CRT warnings when enabled. These warnings were displayed by default until now.
The following php.ini. directives have been changed:
- session.entropy_file now defaults to /dev/random or /dev/urandom depending on what has been guessed at compile time.
- session.entropy_length now defaults to 32.
12. Other changes 别的修改
- The default character set for htmlspecialchars() and htmlentities() is now UTF-8, instead of ISO-8859-1. Note that changing your output charset via the default_charset configuration setting does not affect htmlspecialchars/htmlentities unless you are passing "" (an empty string) as the encoding parameter to your htmlspecialchars()/htmlentities() calls. Generally we do not recommend doing this because you should be able to change your output charset without affecting the runtime charset used by these functions. The safest approach is to explicitly set the charset on each call to htmlspecialchars() and htmlentities().
E_ALL
now includesE_STRICT
level errors in the error_reporting configuration directive.- SNMP now has an OOP API. Functions now return
FALSE
on every error condition including SNMP-related (no such instance, end of MIB, etc). Thus, in particular, breaks previous behavior of get/walk functions returning an empty string on SNMP-related errors. Multi OID get/getnext/set queries are now supported. Dropped UCD-SNMP compatibility code, consider upgrading to net-snmp v5.3+, Net-SNMP v5.4+ is required for Windows version. In sake of adding support for IPv6 DNS name resolution of remote SNMP agent (peer) is done by extension now, not by Net-SNMP library anymore. - OpenSSL now supports AES.
- CLI SAPI doesn't terminate any more on fatal errors when using interactive mode with readline support.
- $_SERVER['REQUEST_TIME_FLOAT'] has been added to include microsecond precision.
- Added new hash algorithms: fnv132, fnv164, joaat
- Chained string offsets - e.g. $a[0][0] where $a is a string - now work.
- Arrays cast from SimpleXMLElement now always contain all nodes instead of just the first matching node. All SimpleXMLElement children are now always printed when using var_dump(), var_export() and print_r().
- It's now possible to enforce the class' __construct arguments in an abstract constructor in the base class.
PHP5.4的变化关注---What has changed in PHP 5.4.x(转)的更多相关文章
- (六)观察者模式详解(包含观察者模式JDK的漏洞以及事件驱动模型)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 本章我们讨论一个除前面的单例 ...
- 设计模式之 观察者模式详解(包含观察者模式JDK的漏洞以及事件驱动模型)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 本章我们讨论一个除前面的单例 ...
- JDK观察者模式和事件机制比较<转>
原文:(六)观察者模式详解(包含观察者模式JDK的漏洞以及事件驱动模型) 作者:zuoxiaolong8810(左潇龙),转载请注明出处. 本章我们讨论一个除前面的单例以及代理模式之外,一个WEB项目 ...
- Backbone源码分析(二)
在传统MVC框架模式中,Model承担业务逻辑的任务.Backbone作为一个mvc框架,主要的业务逻辑交由Model与Collection来实现.Model代表领域对象,今天主要学一下Model源码 ...
- 前端学PHP之面向对象系列第二篇——魔术方法
× 目录 [1]构造方法 [2]析构方法 [3]不可访问属性[4]对象复制[5]字符串[6]对象不存在[7]自动加载类[8]串行化[9]函数调用 前面的话 php在面向对象部分有很多相关的魔术方法,这 ...
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- 从零开始攻略PHP(7)——面向对象(上)
1.理解面向对象的概念 面向对象软件的一个重要优点是支持和鼓励封装的能力.封装也叫数据隐藏. 在面向对象的软件中,对象是一个被保存数据和操作这些数据的操作方法的唯一.可标识的集合. 对象可以按类进行分 ...
- Atitit usbQb212 oo 面向对象封装的标准化与规范解决方案java c# php js
Atitit usbQb212 oo 面向对象封装的标准化与规范解决方案java c# php js 1.1. 封装性是面象对象编程中的三大特性之一 三个基本的特性:封装.继承与多态1 1.2. 魔 ...
- 基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
在上篇<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理>介绍了Bootstrap开发框架的一些基础性概括,包括总体界面效果,以及布局.菜单等内容, ...
随机推荐
- SQL UPDATE 经典
1 sql中用另一个表的一列来更新数据库表 SELECT TOP 1000 [a] ,[b] ,[c] FROM [单元测试项目].[dbo].[A] SELECT TOP 1000 [a] ,[b] ...
- 新手对css的浅识
对于css的一个初步理解与认识 在最近的学习中接触到了之前自己从来都不曾想过的语言,C语言,html超文本标记语言等等,还有今天在这里我要进行分析的css,之前浏览过很多的网页,也曾想过这里面的秘密, ...
- 从头开始学c++,补基础,补踏实
在对c++一知半解的情况下,写c++程序是非常吃力的.对于半路出家写c++的我,写了几个颓废的程序后,再也没有勇气用现有的c++知识去写千疮百孔的程序.非常想写出<整洁的代码>中那样的代码 ...
- 你好,C++(37)上车的人请买票!6.3.3 用虚函数实现多态
6.3.3 用虚函数实现多态 在理解了面向对象的继承机制之后,我们知道了在大多数情况下派生类是基类的“一种”,就像“学生”是“人”类中的一种一样.既然“学生”是“人”的一种,那么在使用“人”这个概念 ...
- 【USACO 2.2.1】序言页码
[题目描述] 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 L 50 M 1000 V 5 C 100 X 10 D 500 最多3个同样的可以表 ...
- git操作(强烈推荐)
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...
- 数据结构 --- 线性表学习(php模拟)
线性表:零个或多个数据元素的有限序列(注:以下都是用的整型数据模拟) 一 顺序存储结构(用一段地址连续的存储单元一次存储线性表的数据元素) 1.1 三个属性:存储空间的起始位置:最大存储容量:当前长度 ...
- php防止sql注入函数
$magic_quotes_gpc = get_magic_quotes_gpc(); @extract(daddslashes($_COOKIE)); @extract(daddslashes($_ ...
- 腾讯QQ、新浪微博等知名社交网络图标素材
腾讯QQ.新浪微博.QQ空间.淘宝.知乎.支付宝.大众点评等设计网络图标矢量素材. 注意是矢量素材,AI格式.放大缩小不变形. 社交网络图标几乎在网页制作中都会用到.一个好看的图标,完全可以提升整体网 ...
- Node.js stream 流学习
由于node.js 创建http 是这样的 http.createServer(function(request,response){}).listen(2000); 里面的request 就是rea ...