Backward incompatible changes

Preventnumber_format()from returning negative zero

Previously, it was possible for thenumber_format()function to return-0. Whilst this is perfectly valid according to the IEEE 754 floating point specification, this oddity was not desirable for displaying formatted numbers in a human-readable form.

<?php

var_dump(number_format(-0.01)); // now outputs string(1) "0" instead of string(2) "-0"

Convert numeric keys in object and array casts

Numeric keys are now better handled when casting arrays to objects and objects to arrays(either from explicit casting or bysettype()).

This means that integer(or stringy integer)keys from arrays being casted to objects are now accessible:

<?php

// array to object
$arr = [0 => 1];
$obj = (object)$arr;
var_dump(
    $obj,
    $obj->{'0'}, // now accessible
    $obj->{0} // now accessible
);

以上例程会输出:

object(stdClass)#1 (1) {
  ["0"]=>    // string key now, rather than integer key
  int(1)
}
int(1)
int(1)

And integer(or stringy integer)keys from objects being casted to arrays are now accessible:

<?php

// object to array
$obj = new class {
    public function __construct()
    {
        $this->{0} = 1;
    }
};
$arr = (array)$obj;
var_dump(
    $arr,
    $arr[0], // now accessible
    $arr['0'] // now accessible
);

以上例程会输出:

array(1) {
  [0]=>    // integer key now, rather than string key
  int(1)
}
int(1)
int(1)

淘宝 adsense 商品推荐

官方正版 Google AdSense实战宝典 用谷歌广告联盟出海赚美元 第2版 祁劲松 网站运营书籍 seo搜索引擎优化 AdSense从入门到精通

价格:37元

Disallow passingNULLtoget_class()

Previously, passingNULLto theget_class()function would output the name of the enclosing class. This behaviour has now been removed, where anE_WARNINGwill be output instead. To achieve the same behaviour as before, the argument should simply be omitted.

Warn when counting non-countable types

AnE_WARNINGwill now be emitted when attempting tocount()non-countable types(this includes thesizeof()alias function).

<?php

var_dump(
    count(null), // NULL is not countable
    count(1), // integers are not countable
    count('abc'), // strings are not countable
    count(new stdclass), // objects not implementing the Countable interface are not countable
    count([1,2]) // arrays are countable
);

以上例程会输出:

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d
int(0)
int(1)
int(1)
int(1)
int(2)

淘宝 云主机 商品推荐

远程电脑出租e5主机云服务器物理机游戏云主机工作室服务器租用

价格:12元

Move ext/hash from resources to objects

As part of the long-term migration away from resources, theHashextension has been updated to use objects instead of resources. The change should be seamless for PHP developers, except for whereis_resource()checks have been made(which will need updating tois_object()instead).

Improve SSL/TLS defaults

The following changes to the defaults have been made:

  • tls:// now defaults to tlsv1.0 or tlsv1.1 or tlsv1.2
  • ssl:// an alias of tls://
  • stream_crypto_method_tls_* constants default to tlsv1.0 or tlsv1.1 + tlsv1.2, instead of tlsv1.0 only

gettype()return value on closed resources

Previously, usinggettype()on a closed resource would return a string of"unknown type". Now, a string of"resource(closed)"will be returned.

is_object()and__PHP_Incomplete_Class

Previously, usingis_object()on the__PHP_Incomplete_Classclass would returnFALSE. Now,TRUEwill be returned.

Promote the error level of undefined constants

Unqualified references to undefined constants will now generate anE_WARNING(instead of anE_NOTICE). In the next major version of PHP, they will generateErrorexceptions.

淘宝 SEO书 商品推荐

官方正版 SEO实战密码 60天网站流量提高20倍 第三版 百度谷歌360首页搜索引擎 优化天猫淘宝标题 关键词标题优化攻略教程书籍

价格:51.8元

Windows support

The officially supported, minimum Windows versions are now Windows 7/Server 2008 R2.

Checks on default property values of traits

Compatibility checks upon default trait property values will no longer perform casting.

objectfor class names

Theobjectname was previously soft-reserved in PHP 7.0. This is now hard-reserved, prohibiting it from being used as a class, trait, or interface name.

NetWare support

Support for NetWare has now been removed.

array_unique()withSORT_STRING

Whilearray_unique()withSORT_STRINGformerly copied the array and removed non-unique elements(without packing the array afterwards), now a new array is built by adding the unique elements. This can result in different numeric indexes.

bcmod()changes with floats

Thebcmod()function no longer truncates fractional numbers to integers. As such, its behavior now followsfmod(), rather than the%operator. For examplebcmod('4', '3.5')now returns0.5instead of1.

淘宝 建站 书 商品推荐

正版 从0到1 HTML+CSS+JavaScript快速上手 网页制作与设计教程 web html5 dw开发建站网站建设 web前端开发书籍 前端静态页面制作

价格:38.3元

Hashing functions and non-cryptographic hashes

Thehash_hmac(),hash_hmac_file(),hash_pbkdf2(), andhash_init()(withHASH_HMAC)functions no longer accept non-cryptographic hashes.

json_decode()function options

Thejson_decode()function option,JSON_OBJECT_AS_ARRAY, is now used if the second parameter(assoc)isNULL. Previously,JSON_OBJECT_AS_ARRAYwas always ignored.

rand()andmt_rand()output

Sequences generated byrand()andmt_rand()for a specific seed may differ from PHP 7.1 on 64-bit machines(due to the fixing of a modulo bias bug in the implementation).

Removal ofsql.safe_modeini setting

Thesql.safe_modeini setting has now been removed.

Changes todate_parse_from_format()

Thezoneelement of the array returned bydate_parse_from_format()represents seconds instead of minutes now, and its sign is inverted. For instance-120is now7200.

淘宝 网站联盟 商品推荐

官方正版 Google AdSense实战宝典 用谷歌广告联盟出海赚美元 第2版 祁劲松 网站运营书籍 seo搜索引擎优化 AdSense从入门到精通

价格:37元