Skip to content

Commit f3cc497

Browse files
committed
Deprecate implicit bool to string coercion
1 parent 7d8e3da commit f3cc497

File tree

102 files changed

+1286
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1286
-134
lines changed

Zend/tests/017.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ string(5) "array"
5151
int(%d)
5252
string(5) "array"
5353
int(%d)
54+
55+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
5456
bool(false)
5557
string(5) "array"
5658
int(%d)

Zend/tests/call_user_func_strict_arginfo_check.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ namespace Foo;
1010
var_dump(call_user_func('strlen', false));
1111

1212
?>
13-
--EXPECT--
13+
--EXPECTF--
14+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
1415
int(0)

Zend/tests/type_declarations/scalar_basic.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ string(%d) "%d"
197197
string(3) "NAN"
198198

199199
*** Trying bool(true)
200+
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
200201
string(1) "1"
201202

202203
*** Trying bool(false)
204+
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
203205
string(0) ""
204206

205207
*** Trying NULL

Zend/tests/type_declarations/scalar_return_basic_64bit.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ string(19) "9223372036854775807"
158158
*** Trying float(NAN)
159159
string(3) "NAN"
160160
*** Trying bool(true)
161+
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
161162
string(1) "1"
162163
*** Trying bool(false)
164+
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
163165
string(0) ""
164166
*** Trying NULL
165167
*** Caught {closure}(): Return value must be of type string, null returned in %s on line %d

Zend/tests/type_declarations/union_types/type_checking_weak.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ INF => "INF"
181181
"42x" => "42x"
182182
"x" => "x"
183183
"" => ""
184-
true => "1"
185-
false => ""
184+
true => "1" (Implicit bool to string coercion is deprecated)
185+
false => "" (Implicit bool to string coercion is deprecated)
186186
null => Argument ... must be of type array|string, null given
187187
[] => []
188188
new stdClass => Argument ... must be of type array|string, stdClass given

Zend/zend_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **des
652652
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("string", arg_num)) {
653653
return 0;
654654
}
655+
if (UNEXPECTED(Z_TYPE_P(arg) == IS_TRUE || Z_TYPE_P(arg) == IS_FALSE)) {
656+
zend_error(E_DEPRECATED, "Implicit bool to string coercion is deprecated");
657+
}
655658
convert_to_string(arg);
656659
*dest = Z_STR_P(arg);
657660
} else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {

ext/iconv/tests/bug48147.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ bool(false)
2020
string(10) "aa%C3%B8aa"
2121

2222
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
23+
24+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
2325
string(0) ""
2426
string(8) "%C3%B8aa"
2527

2628
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
29+
30+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
2731
string(0) ""

ext/iconv/tests/iconv_mime_decode.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ do_regression_test();
7070
(32) "Subject: Prüfung PrüfungkůÔńÓlet"
7171
(31) "Subject: PrüfungPrüfungkůÔńÓlet"
7272
2: iconv_mime_decode(): Malformed string
73+
8192: Implicit bool to string coercion is deprecated
7374
(0) ""
7475
(27) "From: サンプル文字列サンプル文字列日本語テキスト"
7576
(31) "Subject: PrüfungPrüfungkůÔńÓlet"
7677
(32) "Subject: Prüfung PrüfungkůÔńÓlet"
7778
(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?="
7879
2: iconv_mime_decode(): Malformed string
80+
8192: Implicit bool to string coercion is deprecated
7981
(0) ""
8082
(27) "From: サンプル文字列サンプル文字列日本語テキスト"
8183
(31) "Subject: PrüfungPrüfungkůÔńÓlet"

ext/json/tests/bug69187.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var_dump(json_last_error());
2626
json_decode("\"\x00\"");
2727
var_dump(json_last_error());
2828
?>
29-
--EXPECT--
29+
--EXPECTF--
30+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
3031
NULL
3132
int(4)
3233
NULL
@@ -35,6 +36,8 @@ int(0)
3536
int(0)
3637
int(1)
3738
int(0)
39+
40+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
3841
int(1)
3942
int(0)
4043
int(5)

ext/reflection/tests/005.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ foreach($r->getMethods() as $m)
4646
}
4747

4848
?>
49-
--EXPECT--
49+
--EXPECTF--
5050
string(19) "Comment for class A"
5151
string(15) "Method A::bla()"
52+
53+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
5254
bool(false)
55+
56+
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
5357
bool(false)
5458
string(22) "* Comment for A::baz()"

0 commit comments

Comments
 (0)