; PHP5.4的变化关注—What has changed in PHP 5.4.x | Linux运维部落

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) 数组转字符串提示 

1
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 

    1
    FALSE

    .set_magic_quotes_runtime() raises an 

    1
    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 

    1
    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 

    1
    E_WARNING

     if you try to use them. Offsets of types double, bool and null produce a 

    1
    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 

    1
    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 

    1
    E_NOTICE

     level error, but the result of the cast will still be the string "Array".

  • Turning 

    1
    NULL

    1
    FALSE

    , or an empty string into an object by adding a property will now emit an 

    1
    E_WARNING

     level error, instead of 

    1
    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 

    1
    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 

    1
    E_STRICT

     level error is emitted.

The following keywords are now reserved, and may not be used as names by functions, classes, etc.

  • trait

  • callable

  • insteadof

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 新功能

 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:

  • mcrypt_generic_end()

  • mysql_list_dbs()

4. Changed Functions 变化的自带函数

Several functions were given new, optional parameters in PHP 5.4:

PHP Core:

  • Added the optional 

    1
    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()

SPL:

  • class_uses()

Session:

  • session_status()

  • session_register_shutdown()

Mysqli:

  • mysqli_error_list()

  • mysqli_stmt_error_list()

Libxml:

  • libxml_set_external_entity_loader()

LDAP:

  • ldap_control_paged_result()

  • ldap_control_paged_result_response()

Intl:

  • transliterator_create()

  • transliterator_create_from_rules()

  • transliterator_create_inverse()

  • transliterator_get_error_code()

  • transliterator_get_error_message()

  • transliterator_list_ids()

  • transliterator_transliterate()

Zlib:

  • zlib_decode()

  • zlib_encode()

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

The following classes were introduced in PHP 5.4.0:

SPL:

  • CallbackFilterIterator

  • RecursiveCallbackFilterIterator

Reflection:

  • ReflectionZendExtension

Json:

  • JsonSerializable

Session:

  • SessionHandler

  • SessionHandlerInterface

Snmp:

  • SNMP

Intl:

  • Transliterator

  • Spoofchecker

7. New Methods 新增的方法

Several new methods were introduced in 5.4.0:

XSL:

  • XsltProcessor::setSecurityPrefs()

  • XsltProcessor::getSecurityPrefs()

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()

Reflection:

  • ReflectionExtension::isPersistent()

  • ReflectionExtension::isTemporary()

  • ReflectionClass::isCloneable()

Closure:

  • Closure::bind()

  • Closure::bindTo()

PDO_dblib:

  • PDO::newRowset()

StreamWrapper:

  • StreamWrapper::stream_metadata()

  • StreamWrapper::stream_truncate()

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:

    • 1
      ENT_DISALLOWED

    • 1
      ENT_HTML401

    • 1
      ENT_HTML5

    • 1
      ENT_SUBSTITUTE

    • 1
      ENT_XML1

    • 1
      ENT_XHTML

    • 1
      IPPROTO_IP

    • 1
      IPPROTO_IPV6

    • 1
      IPV6_MULTICAST_HOPS

    • 1
      IPV6_MULTICAST_IF

    • 1
      IPV6_MULTICAST_LOOP

    • 1
      IP_MULTICAST_IF

    • 1
      IP_MULTICAST_LOOP

    • 1
      IP_MULTICAST_TTL

    • 1
      MCAST_JOIN_GROUP

    • 1
      MCAST_LEAVE_GROUP

    • 1
      MCAST_BLOCK_SOURCE

    • 1
      MCAST_UNBLOCK_SOURCE

    • 1
      MCAST_JOIN_SOURCE_GROUP

    • 1
      MCAST_LEAVE_SOURCE_GROUP

    Curl:

    • 1
      CURLOPT_MAX_RECV_SPEED_LARGE

    • 1
      CURLOPT_MAX_SEND_SPEED_LARGE

    LibXML:

    • 1
      LIBXML_HTML_NODEFDTD

    • 1
      LIBXML_HTML_NOIMPLIED

    • 1
      LIBXML_PEDANTIC

    OpenSSL:

    • 1
      OPENSSL_CIPHER_AES_128_CBC

    • 1
      OPENSSL_CIPHER_AES_192_CBC

    • 1
      OPENSSL_CIPHER_AES_256_CBC

    • 1
      OPENSSL_RAW_DATA

    • 1
      OPENSSL_ZERO_PADDING

    Output buffering:

    • 1
      PHP_OUTPUT_HANDLER_CLEAN

    • 1
      PHP_OUTPUT_HANDLER_CLEANABLE

    • 1
      PHP_OUTPUT_HANDLER_DISABLED

    • 1
      PHP_OUTPUT_HANDLER_FINAL

    • 1
      PHP_OUTPUT_HANDLER_FLUSH

    • 1
      PHP_OUTPUT_HANDLER_FLUSHABLE

    • 1
      PHP_OUTPUT_HANDLER_REMOVABLE

    • 1
      PHP_OUTPUT_HANDLER_STARTED

    • 1
      PHP_OUTPUT_HANDLER_STDFLAGS

    • 1
      PHP_OUTPUT_HANDLER_WRITE

    Sessions:

    • 1
      PHP_SESSION_ACTIVE

    • 1
      PHP_SESSION_DISABLED

    • 1
      PHP_SESSION_NONE

    Streams:

    • 1
      STREAM_META_ACCESS

    • 1
      STREAM_META_GROUP

    • 1
      STREAM_META_GROUP_NAME

    • 1
      STREAM_META_OWNER

    • 1
      STREAM_META_OWNER_NAME

    • 1
      STREAM_META_TOUCH

    Zlib:

    • 1
      ZLIB_ENCODING_DEFLATE

    • 1
      ZLIB_ENCODING_GZIP

    • 1
      ZLIB_ENCODING_RAW

    Intl:

    • 1
      U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR

    • 1
      IDNA_CHECK_BIDI

    • 1
      IDNA_CHECK_CONTEXTJ

    • 1
      IDNA_NONTRANSITIONAL_TO_ASCII

    • 1
      IDNA_NONTRANSITIONAL_TO_UNICODE

    • 1
      INTL_IDNA_VARIANT_2003

    • 1
      INTL_IDNA_VARIANT_UTS46

    • 1
      IDNA_ERROR_EMPTY_LABEL

    • 1
      IDNA_ERROR_LABEL_TOO_LONG

    • 1
      IDNA_ERROR_DOMAIN_NAME_TOO_LONG

    • 1
      IDNA_ERROR_LEADING_HYPHEN

    • 1
      IDNA_ERROR_TRAILING_HYPHEN

    • 1
      IDNA_ERROR_HYPHEN_3_4

    • 1
      IDNA_ERROR_LEADING_COMBINING_MARK

    • 1
      IDNA_ERROR_DISALLOWED

    • 1
      IDNA_ERROR_PUNYCODE

    • 1
      IDNA_ERROR_LABEL_HAS_DOT

    • 1
      IDNA_ERROR_INVALID_ACE_LABEL

    • 1
      IDNA_ERROR_BIDI

    • 1
      IDNA_ERROR_CONTEXTJ

    Json:

    • 1
      JSON_PRETTY_PRINT

    • 1
      JSON_UNESCAPED_SLASHES

    • 1
      JSON_NUMERIC_CHECK

    • 1
      JSON_UNESCAPED_UNICODE

    • 1
      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().

    • 1
      E_ALL

       now includes 

      1
      E_STRICT

       level errors in the error_reporting configuration directive.

    • SNMP now has an OOP API. Functions now return 

      1
      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,如若转载,请注明出处:/2964

    联系我们

    400-080-6560

    在线咨询:点击这里给我发消息

    邮件:1660809109@qq.com

    工作时间:周一至周五,9:30-18:30,节假日同时也值班

    友情链接:guoqibee.com  万达娱乐平台  万达娱乐主管  万达娱乐直属  万达直属  万达娱乐登录  guoqibee.com  万达娱乐直属QQ  万达主管QQ