Previously, it was possible for the number_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"
Numeric keys are now better handled when casting arrays to object and objects to arrays (either from explicit casting or by settype()).
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)
NULL
to get_class()
Previously, passing NULL
to the get_class() function
would output the name of the enclosing class. This behaviour has now been
removed, where an E_WARNING
will be output instead. To
achieve the same behaviour as before, the argument should simply be omitted
instead.
An E_WARNING
will now be emitted when attempting to
count() non-countable types (this includes the
sizeof() alias function).
<?php
var_dump(
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 int(1) int(1) int(1) int(2)
As part of the long-term migration away from resources, the Hash extension has been updated to use objects instead of resources. The change should be seamless for PHP developers, except for where is_resource() checks have been made (which will need updating to is_object() instead).
The following changes to the defaults have been made:
Previously, using gettype() on a closed resource would return a string of "unknown type". Now, a string of "resource (closed)" will be returned.
Previously, using is_object() on the
__PHP_Incomplete_Class class would return FALSE
.
Now, TRUE
will be returned.
Unqualified references to undefined constants will now generate an
E_WARNING
(instead of an E_NOTICE
).
In the next major version of PHP, they will generate
Error exceptions.
The officially supported, minimum Windows versions are now Windows 7/Server 2008 R2.
Compatibilitiy checks upon default trait property values will no longer perform casting.
The object name 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.
Support for Netware has now been removed.
The bcmod() function no longer truncates fractional numbers to integers. As such, its behavior now follows fmod(), rather than the % operator. For example bcmod('4', '3.5') now returns 0.5 instead of 1.
The hash_hmac(), hash_hmac_file(),
hash_pbkdf2(), and hash_init() (with
HASH_HMAC
) functions no longer accept non-cryptographic
hashes.
The json_decode() function option,
JSON_OBJECT_AS_ARRAY
, is now used if the second
parameter (assoc) is NULL
. Previously,
JSON_OBJECT_AS_ARRAY
was always ignored.