Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ PHP NEWS
using OPcache). (timwolla)
. Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is
configured). (nielsdos)
. Fixed bug GH-19719 (Allow empty statements before declare(strict_types)).
(nielsdos)
. Casting floats that are not representable as ints now emits a warning.
(Girgias)

- Curl:
. Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead
Expand All @@ -21,6 +25,9 @@ PHP NEWS
- Date:
. Fixed GH-17159: "P" format for ::createFromFormat swallows string literals.
(nielsdos)
. The __wakeup() magic method of DateTimeInterface, DateTime,
DateTimeImmutable, DateTimeZone, DateInterval, and DatePeriod has been
deprecated in favour of the __unserialize() magic method. (Girgias)

- Exif:
. Fix OSS-Fuzz #442954659 (zero-size box in HEIF file causes infinite loop).
Expand All @@ -32,6 +39,9 @@ PHP NEWS
. Fixed GH-8157 (post_max_size evaluates .user.ini too late in php-fpm).
(Jakub Zelenka)

- Iconv:
. Extends the ICONV_CONST preprocessor for illumos/solaris. (jMichaelA)

- Opcache:
. Fixed bug GH-19669 (assertion failure in zend_jit_trace_type_to_info_ex).
(Arnaud)
Expand All @@ -53,6 +63,9 @@ PHP NEWS
. Add new Uri\UriError exception that is thrown for internal error
conditions. (timwolla)
. Further clean up the internal API. (timwolla)
. Fixed bug GH-19892 (Refcounting on zend_empty_array). (ilutov, timwolla)
. Fixed handling of port numbers > 65535 with the internal
`php_uri_parse_to_struct()` API. (timwolla)

- Windows:
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ PHP 8.5 UPGRADE NOTES
. Destructing non-array values (other than NULL) using [] or list() now
emits a warning.
RFC: https://wiki.php.net/rfc/warnings-php-8-5#destructuring_non-array_values
. A warning is now emitted when casting floats (or strings that look like
floats) to int if they cannot be represented as one. This affects explicit
int casts and implicit int casts.
RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int

- BZ2:
. bzcompress() now throws a ValueError when $block_size is not between
Expand Down Expand Up @@ -413,6 +417,10 @@ PHP 8.5 UPGRADE NOTES
deprecated. This is because the associated timezone is ignored and always
uses GMT.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_date_rfc7231_and_datetimeinterfacerfc7231
. The __wakeup() magic method of DateTimeInterface, DateTime,
DateTimeImmutable, DateTimeZone, DateInterval, and DatePeriod has been
deprecated in favour of the __unserialize() magic method.
Related to RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_sleep_and_wakeup_magic_methods

- FileInfo:
. The finfo_close() function has been deprecated.
Expand Down
6 changes: 3 additions & 3 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static inline zend_result fetch_array_elem(zval **result, zval *op1, zval *op2)
*result = zend_hash_index_find(Z_ARR_P(op1), Z_LVAL_P(op2));
return SUCCESS;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(op2));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(op2));
if (!zend_is_long_compatible(Z_DVAL_P(op2), lval)) {
return FAILURE;
}
Expand Down Expand Up @@ -459,7 +459,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key)
zend_hash_index_del(Z_ARR_P(result), Z_LVAL_P(key));
break;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(key));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
return FAILURE;
}
Expand Down Expand Up @@ -504,7 +504,7 @@ static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, cons
value = zend_hash_index_update(Z_ARR_P(result), Z_LVAL_P(key), value);
break;
case IS_DOUBLE: {
zend_long lval = zend_dval_to_lval(Z_DVAL_P(key));
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
return FAILURE;
}
Expand Down
1 change: 1 addition & 0 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -5283,6 +5283,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
case ZEND_CAST:
switch (opline->extended_value) {
case IS_LONG:
return (t1 & (MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_OBJECT));
case IS_DOUBLE:
return (t1 & MAY_BE_OBJECT);
case IS_STRING:
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bitwise_not_precision_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ try {
}
?>
--EXPECT--
Implicit conversion from float INF to int loses precision
The float INF is not representable as an int, cast occurred
10 changes: 5 additions & 5 deletions Zend/tests/bug46701.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ new foo;

?>
--EXPECTF--
Deprecated: Implicit conversion from float 3428599296 to int loses precision in %s on line %d
Warning: The float 3428599296 is not representable as an int, cast occurred in %s on line %d

Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d
Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d

Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d
Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d
array(3) {
[-866368000]=>
int(1)
Expand All @@ -41,10 +41,10 @@ array(3) {
int(3)
}

Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d
Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d
int(2)

Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d
Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d
array(1) {
[-835350528]=>
int(3)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug78340.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class lib {

function stream_stat() {
return [
'dev' => 3632233996,
'dev' => PHP_INT_MAX,
'size' => strlen($this->bytes),
'ino' => $this->ino
];
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/falsetoarray_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ $a=[];
?>
DONE
--EXPECTF--
Err: Implicit conversion from float %f to int loses precision
Err: The float %f is not representable as an int, cast occurred
Err: Undefined array key %i
DONE
21 changes: 21 additions & 0 deletions Zend/tests/gh19719.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-19719: Allow empty expressions before declare(strict_types)
--FILE--
<?php
// e.g some comments
?>
<?php

declare(strict_types=1);

function takesInt(int $x) {}

try {
takesInt('42');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECTF--
takesInt(): Argument #1 ($x) must be of type int, string given, called in %s on line %d
11 changes: 10 additions & 1 deletion Zend/tests/int_overflow_32bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ foreach ($doubles as $d) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
Warning: The float 2147483648 is not representable as an int, cast occurred in %s on line %d
int(-2147483648)

Warning: The float 2147483649 is not representable as an int, cast occurred in %s on line %d
int(-2147483647)

Warning: The float 2147483658 is not representable as an int, cast occurred in %s on line %d
int(-2147483638)

Warning: The float 2147483748 is not representable as an int, cast occurred in %s on line %d
int(-2147483548)

Warning: The float 2147484648 is not representable as an int, cast occurred in %s on line %d
int(-2147482648)
Done
8 changes: 7 additions & 1 deletion Zend/tests/int_overflow_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ foreach ($doubles as $d) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
int(9223372036854775807)

Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(-9223372036854775808)

Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(-9223372036854775808)

Warning: The float %f is not representable as an int, cast occurred in %s on line %d
int(0)
int(-9223372036854775808)
int(-9223372036854775808)
Expand Down
10 changes: 9 additions & 1 deletion Zend/tests/int_underflow_32bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ foreach ($doubles as $d) {

echo "Done\n";
?>
--EXPECT--
--EXPECTF--
int(-2147483648)

Warning: The float -2147483649 is not representable as an int, cast occurred in %s on line %d
int(2147483647)

Warning: The float -2147483658 is not representable as an int, cast occurred in %s on line %d
int(2147483638)

Warning: The float -2147483748 is not representable as an int, cast occurred in %s on line %d
int(2147483548)

Warning: The float -2147484648 is not representable as an int, cast occurred in %s on line %d
int(2147482648)
Done
89 changes: 89 additions & 0 deletions Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,93 @@ OUTPUT;

$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';

const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = <<<OUTPUT
Read before write:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: Undefined array key 0 in %s on line %d
NULL
Write:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Read:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(5)
Read-Write:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
isset():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
empty():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
null coalesce:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(25)
Reference to dimension:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Value of reference:
int(25)
Value of container dimension after write to reference (should be int(100) if successful):

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(100)
unset():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested read:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: Undefined array key 0 in %s on line %d

Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested Read-Write:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
Nested isset():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(true)
Nested empty():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
bool(false)
Nested null coalesce:

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d
int(30)
Nested unset():

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

Warning: The float %F is not representable as an int, cast occurred in %s on line %d

OUTPUT;

$EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS) . '$/s';

const EXPECTED_OUTPUT_NULL_OFFSETS = <<<OUTPUT
Read before write:

Expand Down Expand Up @@ -452,6 +539,7 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
Expand Down Expand Up @@ -484,6 +572,7 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OOB_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_NULL_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
Expand Down
Loading