Skip to content
Open
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
8 changes: 8 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ PHP 8.7 UPGRADE NOTES
4. Deprecated Functionality
========================================

- Core:
. Lossy implicit conversions to and from bool for parameter, return, and
property types in coercive typing mode are now deprecated. Converting an
int other than 0 or 1, any float, or a string other than "0" or "1" to
bool emits a deprecation, as does converting a bool to int, float, or
string.
RFC: https://wiki.php.net/rfc/deprecate-lossy-bool-coercion

========================================
5. Changed Functions
========================================
Expand Down
10 changes: 6 additions & 4 deletions Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,20 @@ static uint32_t zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
do {
zend_op *op = call_info->caller_init_opline;

/* Only a bool $strict can be evaluated here. Other values are left to the
* runtime call, which reports lossy coercions and strict_types errors. */
if ((op->opcode == ZEND_FRAMELESS_ICALL_2
|| (op->opcode == ZEND_FRAMELESS_ICALL_3 && (op + 1)->op1_type == IS_CONST))
|| (op->opcode == ZEND_FRAMELESS_ICALL_3 && (op + 1)->op1_type == IS_CONST
&& (Z_TYPE_P(CT_CONSTANT_EX(op_array, (op + 1)->op1.constant)) == IS_TRUE
|| Z_TYPE_P(CT_CONSTANT_EX(op_array, (op + 1)->op1.constant)) == IS_FALSE)))
&& call_info->callee_func
&& zend_string_equals_literal_ci(call_info->callee_func->common.function_name, "in_array")) {
bool strict = false;
bool has_opdata = op->opcode == ZEND_FRAMELESS_ICALL_3;
ZEND_ASSERT(!call_info->is_prototype);

if (has_opdata) {
if (zend_is_true(CT_CONSTANT_EX(op_array, (op + 1)->op1.constant))) {
strict = true;
}
strict = Z_TYPE_P(CT_CONSTANT_EX(op_array, (op + 1)->op1.constant)) == IS_TRUE;
}

if (op->op2_type == IS_CONST
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/arrow_functions/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ try {
}

try {
assert((fn&(int... $args): ?bool => $args[0])(false));
assert((fn&(int... $args): ?bool => $args[0])(0));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
AssertionError: assert((fn() => false)())
AssertionError: assert((fn&(int ...$args): ?bool => $args[0])(false))
AssertionError: assert((fn&(int ...$args): ?bool => $args[0])(0))
142 changes: 3 additions & 139 deletions Zend/tests/backtrace/debug_backtrace_options.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ function doit($a, $b, $how)
{
echo "==default\n";
$how();
echo "==true\n";
$how(true);
echo "==false\n";
$how(false);
echo "==DEBUG_BACKTRACE_PROVIDE_OBJECT\n";
$how(DEBUG_BACKTRACE_PROVIDE_OBJECT);
echo "==DEBUG_BACKTRACE_IGNORE_ARGS\n";
Expand Down Expand Up @@ -48,14 +44,6 @@ foo::statCall("doit", "backtrace_print");
#0 %sdebug_backtrace_options.php(%d): doit('a', 'b', 'debug_print_bac...')
#1 %sdebug_backtrace_options.php(%d): foo->doCall('doit', 'debug_print_bac...')
#2 %sdebug_backtrace_options.php(%d): foo::statCall('doit', 'debug_print_bac...')
==true
#0 %sdebug_backtrace_options.php(%d): doit('a', 'b', 'debug_print_bac...')
#1 %sdebug_backtrace_options.php(%d): foo->doCall('doit', 'debug_print_bac...')
#2 %sdebug_backtrace_options.php(%d): foo::statCall('doit', 'debug_print_bac...')
==false
#0 %sdebug_backtrace_options.php(%d): doit('a', 'b', 'debug_print_bac...')
#1 %sdebug_backtrace_options.php(%d): foo->doCall('doit', 'debug_print_bac...')
#2 %sdebug_backtrace_options.php(%d): foo::statCall('doit', 'debug_print_bac...')
==DEBUG_BACKTRACE_PROVIDE_OBJECT
#0 %sdebug_backtrace_options.php(%d): doit('a', 'b', 'debug_print_bac...')
#1 %sdebug_backtrace_options.php(%d): foo->doCall('doit', 'debug_print_bac...')
Expand Down Expand Up @@ -130,138 +118,14 @@ Array

)

)
==true
Array
(
[0] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => 17
[function] => backtrace_print
[args] => Array
(
[0] => 1
)

)

[1] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => doit
[args] => Array
(
[0] => a
[1] => b
[2] => backtrace_print
)

)

[2] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => doCall
[class] => foo
[object] => foo Object
(
)

[type] => ->
[args] => Array
(
[0] => doit
[1] => backtrace_print
)

)

[3] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => statCall
[class] => foo
[type] => ::
[args] => Array
(
[0] => doit
[1] => backtrace_print
)

)

)
==false
Array
(
[0] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => 19
[function] => backtrace_print
[args] => Array
(
[0] =>
)

)

[1] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => doit
[args] => Array
(
[0] => a
[1] => b
[2] => backtrace_print
)

)

[2] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => doCall
[class] => foo
[type] => ->
[args] => Array
(
[0] => doit
[1] => backtrace_print
)

)

[3] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => %d
[function] => statCall
[class] => foo
[type] => ::
[args] => Array
(
[0] => doit
[1] => backtrace_print
)

)

)
==DEBUG_BACKTRACE_PROVIDE_OBJECT
Array
(
[0] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => 21
[line] => 17
[function] => backtrace_print
[args] => Array
(
Expand Down Expand Up @@ -325,7 +189,7 @@ Array
[0] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => 23
[line] => 19
[function] => backtrace_print
)

Expand Down Expand Up @@ -361,7 +225,7 @@ Array
[0] => Array
(
[file] => %sdebug_backtrace_options.php
[line] => 25
[line] => 21
[function] => backtrace_print
)

Expand Down
2 changes: 0 additions & 2 deletions Zend/tests/builtin_functions/builtin_functions_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var_dump(count(get_defined_functions()));
var_dump(gettype(get_declared_interfaces()));
var_dump(count(get_declared_interfaces()));

var_dump(get_extension_funcs(true));
var_dump(gettype(get_extension_funcs("standard")));
var_dump(count(get_extension_funcs("standard")));
var_dump(gettype(get_extension_funcs("zend")));
Expand All @@ -51,7 +50,6 @@ string(5) "array"
int(%d)
string(5) "array"
int(%d)
bool(false)
string(5) "array"
int(%d)
string(5) "array"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ declare(strict_types=1);
namespace Foo;

// strlen() will be called with strict_types=0, so this is legal.
var_dump(call_user_func('strlen', false));
var_dump(call_user_func('strlen', 25));

?>
--EXPECT--
int(0)
int(2)
4 changes: 3 additions & 1 deletion Zend/tests/constants/bug79919.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ $b = error_log(0);
$b = simplexml_load_string('<xml/>', null, $b);
define(0, $b);
?>
--EXPECT--
--EXPECTF--
0

Deprecated: Implicit conversion from true to int in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/dynamic_call/bug47880.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #47880 (crashes in call_user_func_array())
<?php
class bomb {
static function go($n) {
$backtrace = debug_backtrace(false);
$backtrace = debug_backtrace(0);
$backtrace[1]['args'][1] = 'bomb';
}
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/exit/exit_values.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is
Using false as value:
Exit status is: 0
Output is:

Deprecated: Implicit conversion from false to int in %s on line %d
Using true as value:
Exit status is: 1
Output is:

Deprecated: Implicit conversion from true to int in %s on line %d
Using 0 as value:
Exit status is: 0
Output is:
Expand Down Expand Up @@ -136,11 +136,11 @@ Deprecated: exit(): Passing null to parameter #1 ($status) of type string|int is
Using false as value:
Exit status is: 0
Output is:

Deprecated: Implicit conversion from false to int in %s on line %d
Using true as value:
Exit status is: 1
Output is:

Deprecated: Implicit conversion from true to int in %s on line %d
Using 0 as value:
Exit status is: 0
Output is:
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/property_hooks/recursion.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Test {
}

// Edge-case where recursion happens via isset().
public int $prop2 {
public bool $prop2 {
get { return isset($this->prop2); }
set { }
}
Expand All @@ -32,5 +32,5 @@ object(Test)#1 (1) {
["prop"]=>
int(20)
["prop2"]=>
uninitialized(int)
uninitialized(bool)
}
4 changes: 4 additions & 0 deletions Zend/tests/type_coercion/gh22112.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ GH-22112 (Assertion failure when error handler throws during NaN to bool/string
<?php

set_error_handler(function ($errno, $errstr) {
if ($errno === E_DEPRECATED) {
// Ignore the lossy bool coercion deprecation, so that the NAN warning is reached
return true;
}
throw new Exception($errstr);
});

Expand Down
47 changes: 47 additions & 0 deletions Zend/tests/type_coercion/lossy_bool/casts_unaffected.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
Explicit casts and conditions do not emit lossy bool coercion deprecations
--FILE--
<?php

$values = [2, 0.5, 'false', ''];
foreach ($values as $v) {
var_dump((bool) $v, boolval($v), !$v, $v ? 'yes' : 'no');
$copy = $v;
settype($copy, 'bool');
var_dump($copy);
}
var_dump((string) true, strval(false), (float) true, floatval(false), 'x' . true);
echo true, false, "\n";

function mixed_param(mixed $v) { return $v; }
var_dump(mixed_param('false'));

?>
--EXPECT--
bool(true)
bool(true)
bool(false)
string(3) "yes"
bool(true)
bool(true)
bool(true)
bool(false)
string(3) "yes"
bool(true)
bool(true)
bool(true)
bool(false)
string(3) "yes"
bool(true)
bool(false)
bool(false)
bool(true)
string(2) "no"
bool(false)
string(1) "1"
string(0) ""
float(1)
float(0)
string(2) "x1"
1
string(5) "false"
Loading
Loading