Most improvements in PHP 5.4.x have no impact on existing code. There are a and that should be considered, and code should be tested before switching PHP versions in production environments.
1. Backward Incompatible Changes :一些内容将不兼容
7) 注意非数字数组键值 详看:
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:
- is no longer supported. Any applications that rely on safe mode may need adjustment, in terms of security.
- has been removed. Applications relying on this feature may need to be updated, to avoid security issues. and now always return
FALSE
. raises anE_CORE_ERROR
level error. - The and php.ini directives have been removed.
- has been removed.
- The and statements no longer accept variable arguments (e.g., break 1 + foo() * $bar;). Static arguments still work, such as break 2;.
- In the , the timezone can no longer be set using the TZ environment variable. Instead you have to specify a timezone using the php.ini option or 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 and true on , 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 have been removed.
- now returns array() instead of
FALSE
when two empty arrays are provided as parameters. - If you use with asian character sets, it works like - 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 , and may not be used as names by functions, classes, etc.
- callable
The following functions have been removed from PHP:
- , and .
- The aliases , , , , , , , 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 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].
- now support $this.
- <?= is now always available, regardless of the 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 of files.
- Built-in development .
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: , , and 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 and , to limit the amount of stack frames returned. - 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 and functions.
Intl:
- and 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:
6 . New Classes and Interfaces 新增的类和接口
The following classes were introduced in PHP 5.4.0:
:
:
:
:
:
:
7. New Methods 新增的方法
Several new methods were introduced in 5.4.0:
:
:
- SplQueue::serialize()
- SplQueue::unserialize()
- SplStack::serialize()
- SplStack::unserialize()
- SplTempFileObject::fputcsv()
:
:
:
- 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.
- - Note that ext/sqlite3 and ext/pdo_sqlite are not affected
9 .Other changes to extensions 修改的扩展
Changes in extension behavior, and new features:
- - now implements
- - Removed support for linking with MySQL client libraries older than 4.1
- The MySQL extensions , and use as the default library now. It is still possible to use libmysql by specifying a path to the configure options.
- - 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
:
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_ENCODING_DEFLATE
ZLIB_ENCODING_GZIP
ZLIB_ENCODING_RAW
:
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_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:
- and
- , , and
- and
- , , , , , and
The following php.ini directives have been added:
- and for CLI SAPI using readline in interactive mode.
- to enable the built-in development web server to use ANSI color coding in terminal output.
- - specifies how many GET/POST/COOKIE input variables may be accepted.
- - to control the new multibyte support.
- - This value will be used unless a "declare(encoding=...)" directive appears at the top of the script.
- - to check for replaced signal handlers on shutdown.
- , , , , ,
- - When it's disabled, the POST data is not read (and processed)
- - 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:
- now defaults to /dev/random or /dev/urandom depending on what has been guessed at compile time.
- now defaults to 32.
12. Other changes 别的修改
- The default character set for and is now UTF-8, instead of ISO-8859-1. Note that changing your output charset via the configuration setting does not affect htmlspecialchars/htmlentities unless you are passing "" (an empty string) as the encoding parameter to your / 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 and .
E_ALL
now includesE_STRICT
level errors in the configuration directive.- 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. - now supports AES.
- doesn't terminate any more on fatal errors when using interactive mode with readline support.
- 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 now always contain all nodes instead of just the first matching node. All children are now always printed when using , and .
- It's now possible to enforce the class' arguments in an abstract constructor in the base class.