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  :一些內容將不兼容 

1)不再支持安全模式,

2) 移除魔術引用,

3) 移除全局變量php.ini設置,

4) 移除Call-time pass by reference(如call_user_func_array('function', array(&$a) 不支持)

5)break/continue 不接受參數,但保留接受靜態參數

6)必須設置時區timezone

7) 注意非數字數組鍵值 詳看:PHP5.4中一個需要注意的變化(Chained string offsets) 

8) 數組轉字符串提示 E_NOTICE level error

8) 使用超全局變量做函數參數將導致致命錯誤

 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 an E_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 a E_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 a E_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 NULLFALSE, or an empty string into an object by adding a property will now emit an E_WARNING level error, instead of E_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:

2. New features 新功能

 1)traits特性的功能相當使一個類可以存在兩個父類。在php5.4之前,一個類不能繼承兩個父類。

   2)數組可以類似c/c++寫法

   3)Class::{expr}() 這個寫法有點迷糊

  4)支持二進制數值,即二進制直接寫賦值給變量:

$bin  = 0b1101;  
echo $bin;  
 //13

而不必使用bin2dec轉換成十進制

       想看大鳥:二進制直接量(binary number format) 

  5)上傳進度支持(Upload progress in sessions) 

  6)php5.4可以編譯成命令行模式的server

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:

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:

SPL:

Session:

Mysqli:

Libxml:

LDAP:

Intl:

Zlib:

6 . New Classes and Interfaces 新增的類和接口

The following classes were introduced in PHP 5.4.0:

SPL:

Reflection:

Json:

Session:

Snmp:

Intl:

7. New Methods 新增的方法

Several new methods were introduced in 5.4.0:

XSL:

SPL:

Reflection:

Closure:

PDO_dblib:

  • PDO::newRowset()

StreamWrapper:

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:

  • pdo_mysql – Removed support for linking with MySQL client libraries older than 4.1

  • The MySQL extensions mysqlmysqli 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:

    • LIBXML_HTML_NODEFDTD

    • LIBXML_HTML_NOIMPLIED

    • LIBXML_PEDANTIC

    OpenSSL:

    • OPENSSL_CIPHER_AES_128_CBC

    • OPENSSL_CIPHER_AES_192_CBC

    • OPENSSL_CIPHER_AES_256_CBC

    • OPENSSL_RAW_DATA

    • OPENSSL_ZERO_PADDING

    Output buffering:

    • 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

    Sessions:

    • PHP_SESSION_ACTIVE

    • PHP_SESSION_DISABLED

    • PHP_SESSION_NONE

    Streams:

    • 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:

    The following php.ini directives have been added:

    The following php.ini. directives have been changed:

    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 includes E_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.

    轉自:http://blog.csdn.net/hguisu/article/details/7492641

    原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/2964

    (0)
    s19930811s19930811
    上一篇 2015-06-17 10:05
    下一篇 2015-06-17 10:08

    相關推薦

    • N25第1周作業

      1.計算機的組成及功能 地址:博客園http://www.cnblogs.com/qingyangzi/p/6133274.html 2.linux主要的發行版及其區別和聯系 地址:博客園http://www.cnblogs.com/qingyangzi/p/6135801.html 3.linux哲學思想 地址:博客園http://www.cnblogs.…

      Linux干貨 2016-12-05
    • 上古神器之vim

      sed 前言:前面學到了文本處理三劍客之一grep,但是grep在有些時候顯得力不從心,我們需要一款針對行操作的處理工具,沒錯,這就是sed流編輯器。 sed用法提煉: sed 's/(text1)(text2)(text3)/\1\2\3/'  vim 前言:強大的Linux如果沒有一款瘋狂的編輯器,常用的編輯操作會…

      Linux干貨 2016-08-12
    • RAID 0 軟件實現

      RAID 0 軟件實現        RAID 0又稱為Stripe或Striping,它代表了所有RAID級別中最高的存儲性能。RAID 0提高存儲性能的原理是把連續的數據分散到多個磁盤上存取,這樣,系統有數據請求就可以被多個磁盤并行的執行,每個磁盤執行屬于它自己的那部分數據請求。這種數據上的并行…

      Linux干貨 2017-05-02
    • 壓縮、解壓縮及歸檔工具

      壓縮、解壓縮及歸檔工具 縮文件的基本原理是查找文件內的重復字節,并建立一個相同字節的"詞典"文件,并用一個代碼表示,比如在文件里有幾處有一個相同的詞"中華人民共和國"用一個代碼表示并寫入"詞典"文件,這樣就可以達到縮小文件的目的。         &#8212…

      Linux干貨 2016-08-18
    • HipHop PHP實戰(詳解web運行模式)

      Note: These code examples assume the HipHop compiler is fully built. 1 . Setting Up Your Environment (構建環境) To get started, you need to configure two environment variables. cd…

      Linux干貨 2015-04-10
    • 網卡別名及多網卡配置

      網卡別名 對于要在不同網段環境中使用的設備有很大的幫助。     要使用網卡別名首先要關閉NetworkManager這個服務,防止在后續操作中引起不必要的沖突。 [root@laodeng6 ~]# chkconfig NetworkManager off [root@laod…

      Linux干貨 2016-09-06
    欧美性久久久久