Contents
- Introduction
- History
- Proposal
- Conversion matrix
- Examples
- Deprecation message format
- Unaffected PHP functionality
- Union types
- NAN
- Counter-arguments
- "This adds a separate set of boolean rules for type declarations"
- "Coercive mode exists to accept loosely typed input"
- "Developers will just add casts"
- "Why not just enable strict_types?"
- "Why not rely on static analysis?"
- "Are the 0/1 and "0"/"1" values arbitrary?"
- "Why deprecate "" when it converts to false today?"
- "Why accept 0/1 for bool, but not bool for int?"
- Backward Incompatible Changes
- in_array() with a constant $strict argument
- Migration guide
- Proposed PHP Version
- RFC Impact
- To Existing Code
- To the Ecosystem
- To Existing Extensions
- To SAPIs
- Performance
- Voting Choices
- Patches and Tests
- Appendix: Test Suite Analysis
- php-src test suite
- Symfony test suite
- Laravel test suite
- Comparison with the 2025 proposal
- References
- Rejected Features
- Changelog
Introduction
For most scalar types, when strict_types is not enabled PHP allows safe conversions and rejects or deprecates conversions that would lose information. Since PHP 8.0, for example, passing "1abc" to an int parameter throws a TypeError instead of accepting it as 1 with a notice,[1] and since PHP 8.1, passing 0.1 emits a deprecation notice instead of silently truncating it to 0.[2]
The bool type has never received similar safeguards. Every scalar value is accepted for a bool declaration and silently reduced to true or false. In the other direction, true and false are silently converted to 1/0, "1"/"", or 1.0/0.0 when passed to int, string, or float declarations.
As a result, type declarations fail at one of their primary purposes: catching a value of the wrong type passed by mistake. The silent conversion discards the value's original meaning, turning mistakes and errors into plausible-looking values that carry forward and surface later as incorrect state or output.
For example, a pair of scalar arguments may be accidentally swapped, resulting in a call that looks reasonable and runs without any warning:
// header(string $header, bool $replace = true, int $response_code = 0)
header('Location: /new-url', 301);
Here 301 is coerced to true for $replace, while $response_code stays 0. PHP therefore sends 302 Found instead of 301 Moved Permanently. The mistake is silent and may only be discovered by inspecting the response.
A boolean and a number can also be swapped in business logic, with more serious consequences:
// Order::applyDiscount(float $rate, bool $stackable)
$order->applyDiscount($coupon->isStackable(), $coupon->getRate());
// true becomes 1.0 (a 100% discount). 0.1 becomes true (stackable)
Strings are accepted for bool declarations regardless of their content, so "false", "off", and "no" all become true:
// User::setNotifications(bool $enabled)
$user->setNotifications($_POST['notifications']); // "false" enables notifications
In the other direction, a false returned on failure is accepted for a string declaration and converted to "":
function renderJson(mixed $data): string
{
return json_encode($data); // false on failure becomes ""
}
http_response_code(200);
echo renderJson(['name' => "\xB1"]); // invalid UTF-8: empty body, HTTP 200
false becoming "" is especially dangerous in security checks, because an empty string matches everything in functions like str_starts_with() and str_contains():
if (!str_starts_with($redirectUrl, getenv('APP_URL'))) {
$redirectUrl = '/'; // don't redirect to external sites
}
// APP_URL not set: false becomes "", so every URL passes the check
A false passed to an int or float declaration is similarly converted to 0 or 0.0:
$dueDate = date('Y-m-d', strtotime($_POST['due_date']));
// invalid input: false becomes timestamp 0, so the due date becomes the Unix epoch
array_splice($items, array_search($id, $items), 1);
// $id not found: false becomes offset 0, so the first item is removed
History
A few previous RFCs have attempted to address these issues, but none were accepted.
In 2021, Deprecate boolean to string coercion proposed deprecating conversions from bool to string, not only for type declarations but also in string contexts such as echo, concatenation, and interpolation. Because booleans are commonly output this way, the change was expected to be too disruptive, and the RFC was not brought to a vote.
In 2022, Stricter implicit boolean coercions focused on conversions to bool, proposing to deprecate them for all scalar values except 0, 0.0, -0.0, "", "0", 1, 1.0, and "1". It was declined with 3 votes in favor and 14 opposed. The main objection was that it introduced a separate, context-specific set of boolean rules for type declarations. Its allowed values, which included 0.0, -0.0, and 1.0 but no other floats, were seen as arbitrary, and it did not address booleans passed to other scalar types.
In 2025, Deprecate type juggling to and from bool type within the function type juggling context took a more comprehensive approach, deprecating every scalar conversion to and from bool for type declarations. However, this included int 0/1 to bool, the representation used by boolean database columns and functions like preg_match(). The RFC did not include an analysis of its impact on existing code, and when the implementation was tested against Symfony during the discussion, it emitted a large number of deprecations from correct code. While it received more support than the 2022 proposal, it was still declined with 10 votes in favor and 11 opposed.
Although the 2022 and 2025 RFCs were declined, their implementations demonstrated that the current bool conversion behavior hides real mistakes. The authors found numerous bugs in php-src's own tests, such as the strings "success"/"failed" and "multipart" passed to bool parameters, and false coerced into other scalar parameters.
Proposal
In coercive mode (strict_types not enabled), emit an E_DEPRECATED notice whenever a value is converted to or from bool for a type declaration, except for int 0/1 and string "0"/"1" to bool. This applies to arguments passed to internal and userland functions and methods, return values, and typed properties. In the next major version (PHP 9.0), these conversions will throw a TypeError, like the lossy float to int conversions deprecated in PHP 8.1.
This approach avoids the problems which blocked earlier proposals. Unlike the 2021 RFC, it is limited to type declarations, so echo, concatenation, and interpolation are unaffected. Unlike the 2022 RFC, it covers conversions in both directions and treats all floats the same, instead of allowing only 0.0, -0.0, and 1.0. Unlike the 2025 RFC, it preserves the canonical 0/1 and "0"/"1" representations used by boolean database columns, query parameters, and preg_match(), which are common in correct, frequently executed code (see Impact).
Conversion matrix
| Source | Target | Current behavior | Proposed |
|---|---|---|---|
int 0 / 1 |
bool |
false / true |
allowed |
int other than 0 / 1 |
bool |
true |
deprecated |
float (any, including 0.0 and 1.0) |
bool |
false for 0.0/-0.0, true otherwise |
deprecated |
string "0" / "1" |
bool |
false / true |
allowed |
string other |
bool |
false for "", true otherwise |
deprecated |
bool |
int |
0 / 1 |
deprecated |
bool |
string |
"" / "1" |
deprecated |
bool |
float |
0.0 / 1.0 |
deprecated |
"" is deprecated even though it converts to false today (see Counter-arguments).
Examples
Passing scalars to a bool parameter:
function setEnabled(bool $enabled): void {}
setEnabled(0); // false -- allowed
setEnabled(1); // true -- allowed
setEnabled('0'); // false -- allowed
setEnabled('1'); // true -- allowed
setEnabled(2); // true -- deprecated
setEnabled(0.0); // false -- deprecated
setEnabled('false'); // true -- deprecated
setEnabled(''); // false -- deprecated
setEnabled(' '); // true -- deprecated
setEnabled('0 '); // true -- deprecated
setEnabled('0.0'); // true -- deprecated
Passing booleans to other scalar parameters:
function setCount(int $count): void {}
function setRatio(float $ratio): void {}
function setName(string $name): void {}
setCount(true); // 1 -- deprecated
setCount(false); // 0 -- deprecated
setRatio(true); // 1.0 -- deprecated
setName(true); // "1" -- deprecated
setName(false); // "" -- deprecated
Deprecation message format
The message names the original type and value, and the type it is converted to:
Deprecated: Implicit conversion from int 2 to bool in %s on line %d
Deprecated: Implicit conversion from string "false" to bool in %s on line %d
Deprecated: Implicit conversion from false to int in %s on line %d
Unaffected PHP functionality
This RFC does not change PHP's truthiness rules in conditions, the ternary operator, &&, ||, !, empty(), or isset(). It also does not change:
echo,print, string concatenation, or interpolation- arithmetic, bitwise, or comparison operators on scalar values (for GMP and
BcMath\Numberoperands, see To Existing Extensions) - array keys or offsets
- explicit casts such as
(bool) $valueand(string) $flag, orboolval(),intval(),floatval(),strval(), andsettype() filter_var()withFILTER_VALIDATE_BOOLEAN- calls made from files with
strict_types=1, or return statements and property assignments in those files, since strict mode already rejects these conversions - the
trueandfalsesingleton types, which already reject every coercion - the handling of
null, arrays, objects, and resources, which are already covered by existing rules mixedparameters and return types, where no coercion takes place (for example,file_put_contents()currently does not warn when$dataisfalse)
Union types
The deprecation is emitted only when a value is actually coerced to bool (or from bool to another scalar type). Unions follow the existing preference order: int, float, string, bool. A union that includes bool accepts an actual boolean as-is, so conversions from bool only occur for unions without it.
function f(int|bool $value): void {}
f('yes'); // bool true: deprecated
f('2'); // int 2: no deprecation, bool not selected
function g(int|string $value): void {}
g(true); // int 1: deprecated
function h(string|bool $value): void {}
h(2); // string "2": no deprecation, bool not selected
NAN
Passing NAN to a bool declaration emits the deprecation in addition to the existing PHP 8.5 “unexpected NAN value was coerced to bool” warning, so code which relies on the warning still receives it. If an error handler throws for the deprecation, the warning is not reached. Explicit casts and conditions continue to emit only the warning.
Counter-arguments
"This adds a separate set of boolean rules for type declarations"
PHP already distinguishes between testing a value and accepting it for a declared type. Conditions ask whether a value is truthy and accept null, arrays, objects, and resources, all of which a bool declaration already rejects. Other scalar types draw the same line: (int) 'abc' is 0, but passing 'abc' to an int parameter is a TypeError. Likewise, (int) 1.5 is 1, but passing 1.5 is deprecated. A typed parameter declares that the value is a boolean, not that the function wants to test its truthiness.
This RFC does not add any new conversion results. Every value which remains allowed converts exactly as if and (bool) would convert it, so there is no second table of results to remember. There is only the rule that already applies to int and float: a type declaration accepts values which unambiguously represent the type. Whenever truthiness is what the code intends, if ($value) and (bool) $value remain available unchanged.
"Coercive mode exists to accept loosely typed input"
Coercive mode accepts input such as $_GET values, but for other types it already validates that input: '5' is accepted for an int parameter, while 'abc' is rejected. This RFC applies the same principle to bool. The "0" and "1" produced by forms, query strings, and databases remain accepted. Values like "false", "off", and "no" are exactly the ones where silent conversion to true is often wrong.
HTML checkboxes submit "on" by default, but an unchecked checkbox submits nothing at all, so the correct check is isset($_POST['subscribe']) rather than a conversion of the value. Code which genuinely means “any non-empty string is true” can make this explicit with (bool) $value.
"Developers will just add casts"
Some deprecations will be resolved with a cast, but a cast is a deliberate decision which can be reviewed and searched for. Most of the mistakes this RFC targets are not fixed by casting: swapped arguments are fixed by reordering them, and a false failure sentinel by handling the failure.
"Why not just enable strict_types?"
strict_types can help avoid bugs in some cases, but it is not a complete replacement or practical for all existing code:
- It is all-or-nothing per file, so enabling it can require unrelated changes first.
- It is determined at the call site, so a library cannot force its callers to enable it.
- Callbacks invoked by the engine do not reliably inherit the caller's strictness.
- Dynamic and generated code, templates, and
mixedvalues limit how much of a codebase can be made strict.
Enabling it indiscriminately can also make input handling less safe. Since user input arrives as strings, strict types are often satisfied with explicit casts, which accept anything: (int) '5abc' is 5 and (bool) 'false' is true, whereas coercive typing rejects '5abc' for an int parameter. This RFC extends that built-in validation to bool without requiring files to opt in, and provides a gradual migration path to fix bugs surfaced by the deprecation.
"Why not rely on static analysis?"
Static analysis is valuable and catches many of these cases, but it is optional, requires accurate type information, and cannot resolve every dynamic call. Values from json_decode(), request data, a database, arrays, and options are often mixed, so an analyzer may not report a mismatch with a bool parameter, while at runtime the call goes through coercive typing and this RFC emits a deprecation.
Even projects which use static analysis benefit from the runtime check. Symfony runs Psalm and PHPStan in CI, and Laravel runs PHPStan, but the deprecation still surfaced bugs in both projects' source code as well as in their tests, which are not analyzed (see Test Suite Analysis). Projects choose analysis levels, baselines, and paths which suit them.
"Are the 0/1 and "0"/"1" values arbitrary?"
No, although they are not the only way booleans are encoded. They are the most widely used: databases without a native boolean type store and return booleans as 0 and 1, and the same values are common in query strings, environment variables, and APIs. Other integers, such as status codes, IDs, and counts, do not represent booleans and can result from accidentally swapped arguments, as in the header() example. Floats have no conventional boolean encoding, and a computed float may differ from 0.0 or 1.0 by a rounding error, so all float to bool conversions are deprecated. Other encodings, such as PostgreSQL's "t"/"f" and human-readable strings like "true", "false", "yes", and "on", are not standardized across PHP and external systems, and converting them implicitly is often wrong ("f" and "false" both become true today), so they are left to explicit parsing with filter_var() or a comparison.
"Why deprecate "" when it converts to false today?"
Similar to null, an empty string indicates that no value was provided, not that the value is false. While it's correct for missing values to be falsy in a condition, type declarations already reject them in other cases: a non-nullable bool declaration rejects or deprecates null, and an int declaration rejects "" instead of treating it as 0.
Empty strings typically come from optional text fields, such as an address, city, or phone number, so one reaching a bool parameter is usually a sign that the wrong argument was passed:
// Contact::__construct(string $name, string $email, bool $subscribed = false, string $phone = '')
$contact = new Contact($_POST['name'] ?? '', $_POST['email'] ?? '', $_POST['phone'] ?? '');
Here the phone number is passed to $subscribed instead of $phone. A phone number like "555-0100" is deprecated like any other string, but if "" remained allowed, the mistake would only be reported for users who entered one.
Deprecating "" also surfaced mistakes in the php-src and Laravel test suites (see Test Suite Analysis). It does affect some intentional code: since PHP converts false to "", a boolean which was cast or concatenated into a string can come back as "", as with the ESI onerror flag in Symfony's HTTP cache. Such code can produce "0" instead (e.g. $flag ? '1' : '0'), or make the conversion explicit with (bool) $value.
"Why accept 0/1 for bool, but not bool for int?"
When 0 or 1 is passed to a bool parameter, it maps directly to false or true, so nothing is lost. When a boolean is passed to an int parameter, the function receives a number and cannot tell whether the caller meant 0 or passed a false failure sentinel, as in the array_splice() example. Code which stores a boolean as an integer, such as a setter for a boolean database column, can declare the parameter as bool instead, and still accept 0 and 1 from the database.
Backward Incompatible Changes
This RFC adds new E_DEPRECATED notices in coercive mode for the conversions described in the Proposal. Apart from the notices, and the in_array() fix below, behavior is unchanged in PHP 8.x.
in_array() with a constant $strict argument
The compiler and optimizer evaluate a constant $strict argument of in_array() ahead of time, using truthiness instead of the parameter's type check. Without a change, in_array($needle, $haystack, 'no') would not report the deprecation. This ahead-of-time evaluation is now limited to true and false, so other values go through the regular call.
As a side effect, in_array($needle, $haystack, 1) in a file with strict_types=1 now throws a TypeError, as it would for any other bool parameter. Previously it was silently treated as true.
Migration guide
- Boolean parameters: compare explicitly (e.g.
$value === 'yes'), parse withfilter_var($value, FILTER_VALIDATE_BOOLEAN), or cast with(bool) $valuewhen the current truthiness behavior is intended. - Integer tests: compare explicitly instead of returning an integer from a
boolfunction, e.g.($flags & self::FLAG) !== 0orcount($items) > 0. - Failure sentinels: check
=== falsebefore passing or returning the value (e.g. report a validation error whenstrtotime()returnsfalse), or useJSON_THROW_ON_ERRORforjson_encode(). - Boolean to string: when a boolean is intentionally passed as a string (e.g.
$element->setAttribute('data-active', $isActive)), write out the representation the consumer expects, such as$isActive ? 'true' : 'false'or$isActive ? '1' : '0'. - Boolean to int or float: where the value represents a boolean, declare the parameter or property as
bool, which still accepts0and1. Otherwise use an explicit number (e.g.(int) $flagor$flag ? 1.0 : 0.0), fix swapped arguments, or use$a <=> $binstead of$a > $bin comparison callbacks declared to returnint.
The deprecation notice includes the value and points at the exact line, so affected sites can be found by running tests with E_DEPRECATED enabled. Static analysis can find many of them before the code runs.
Proposed PHP Version
Next PHP 8.x (PHP 8.7). The deprecation will be promoted to a TypeError in the next major version (PHP 9.0).
RFC Impact
To Existing Code
The implementation was run against the test suites of php-src, Symfony, and Laravel (see Test Suite Analysis). Only 0.4% of Symfony's tests and 0.6% of Laravel's emitted the new deprecation. Of the places which need to change, almost half are bugs in Symfony, and more than two thirds are bugs in Laravel. In php-src, apart from tests which deliberately exercise type juggling, about 0.5% of the tests emitted the deprecation, all because of mistakes in the tests. The 2025 proposal would have nearly doubled the places to fix in Symfony without surfacing any more bugs, and since these places are in frequently executed code, they would have flooded logs and test output with far more deprecation notices (see Comparison with the 2025 proposal).
To the Ecosystem
IDEs and language servers need no syntax changes. Static analyzers already report many of these mismatches, and this RFC gives them a runtime behavior to match. Migration tools could automatically add explicit comparisons where the intent is clear, such as in a bool function which returns a count() result or a bitmask check. Other deprecations may point to bugs, so they should be reviewed rather than silenced with a cast. Test suites which convert E_DEPRECATED to exceptions may need to update fixtures.
To Existing Extensions
Extension functions parse their arguments with the engine's parameter parsing API (zend_parse_parameters() and the Z_PARAM_* macros), which emits the deprecation, so extensions need no changes for their bool, int, float, and string parameters to be covered. Extensions which accept any value and convert it themselves, for example with zend_is_true() or zval_get_long(), keep their current behavior, just like explicit casts. No exported function signatures change, so there is no ABI change, though extension tests may need updated expectations.
The GMP and BCMath operator overloads convert their operands like method arguments, so new BcMath\Number(1) + true emits the deprecation, just as new BcMath\Number(1) + 1.5 already emits the float to int deprecation.
To SAPIs
No impact. The diagnostics are emitted by the engine like existing coercion deprecations.
Performance
The check only runs when a value needs coercion at a type boundary, so values which already match the declared type, such as a bool passed to a bool parameter, are unaffected. When a value is coerced, the check adds only a type comparison and, for int and string values converted to bool, a comparison against 0/1 or "0"/"1", which is similar to the existing float to int check.
Voting Choices
Primary vote requiring a 2/3 majority to accept the RFC:
Vote: Deprecate lossy conversions to and from bool as outlined in the RFC? — Yes: 0 · No: 0 · Abstain: 0 (closed)
Voting is not yet scheduled. This section will be updated later in the discussion period.
Patches and Tests
The implementation is in php-src PR #25889.
The engine change is small, because the deprecations are emitted by the existing coercion helpers, which already handle arguments to internal and userland functions, return values, typed properties, and union types.
The tests cover arguments, return values, typed properties, internal and userland functions, union types, strict_types=1, explicit casts, the allowed 0/1 and "0"/"1" values, NAN, INF, -0.0, "", "false", whitespace-padded strings, deprecations converted to exceptions, and the interaction with the existing NAN warning. They pass with and without OPcache and the tracing JIT.
The following prior implementations were helpful references, although neither implements exactly this proposal:
- php-src PR #8565 for the 2022 stricter boolean coercion RFC
- php-src PR #18879 for the 2025 bool type juggling RFC
Appendix: Test Suite Analysis
The results below were collected between November 24 and 29, 2026, using php-src master at 98fae349589, the Symfony 8.2 development branch at 1941bd08, and the Laravel 13.x branch at 321caf7 (v13.44.1). The Symfony and Laravel test suites were run on a Windows x64 build, and the php-src test suite on that build and in php-src's CI. The deprecations in each test suite are grouped by cause (a place in the code which needs to change) and classified as a bug or intentional usage.
php-src test suite
Of the roughly 23,000 tests which php-src's CI runs on each platform (Linux x64 and 32-bit, Windows, macOS, and FreeBSD), 288 (1.3%) emitted the new deprecation on at least one platform.
A majority of the affected tests (179) pass booleans or other scalars on purpose, mostly tests written between 2007 and 2009 which feed every type of value to math, string, and filesystem functions. Since parameter type juggling doesn't need to be tested separately for each function, the implementation removes these inputs, or the whole test when that was its only purpose. Only 22 tests still use the deprecated conversions, almost all of them tests of the coercion behavior itself, so few tests will need to change again when the deprecation becomes a TypeError.
The other 109 tests contained mistakes which the deprecation surfaced, which the proposed implementation fixes rather than updating expected output:
- Misplaced parenthesis (31 tests, 3 places): a helper shared by 29
polltests, and two stream tests, chose a socket domain with:
$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? STREAM_PF_INET : STREAM_PF_UNIX);
strtoupper() received the result of the comparison rather than the first 3 characters of PHP_OS, and the code only worked because true and false become "1" and "", which the ternary treats the same.
Iterator::valid(): boolreturning other values (10 tests): the current filename string in 9 Phar tests (a file named"0"would end the iteration early), and an int counter in 1 test.- Failure sentinels passed on (30 tests):
strlen()called on afalsedoc comment before checking forfalse(2 Reflection tests) and on the result of a failedfread()(2 tests),falsefromfgets(),inet_pton(),iconv_mime_decode(),fread(),file_get_contents(),tempnam(),curl_exec(),mb_ereg_replace(),locale_get_display_name(), and a test helper passed on to other string functions (14 tests),falsefrommktime()andimageloadfont()passed tointparameters (2 tests),falsefromgetenv()passed as a database user and password (2 tests), andfalsefromfgets()at the end of a stream returned from?stringmethods of the FPM and OpenSSL test helpers (8 tests). - Wrong return type (4 tests):
__call()methods used asarray_any()/array_all()/array_find()/array_find_key()predicates were declared to returnstring, while returning a bool. - Arbitrary values for
boolparameters and properties (6 tests):ini_get_all("", ""),strstr('', ' ', ''),substr_compare(..., -5), where-5was passed as$case_insensitive,'aoeu'passed as the$compiledparameter ofIntlRuleBasedBreakIterator::__construct(),""passed as the$useIncludePathparameter oftidy_repair_file(), and"45"assigned to theboolpropertySNMP::$oid_increasing_check. falseinstead of an empty string (2 tests):bind_textdomain_codeset(false, false)andlocale_lookup($locales, false, true), which only worked becausefalsebecomes"".- Booleans for parameters which used to be
bool, but are nowintflags (8 tests):ob_start($callback, 0, false)in 6 output buffering tests, from before PHP 5.4 replacedbool $erasewithint $flags,openssl_decrypt($data, $cipher, $passphrase, false, $iv), from before PHP 5.4 replacedbool $raw_inputwithint $options, anddebug_backtrace(false), from before PHP 5.3.6 replacedbool $provide_objectwithint $options.falsehappens to mean “no flags”, buttruedoes not keep its old meaning:ob_start($callback, 0, true)passes flags1, which makes the buffer impossible to erase, the opposite of$erase = true. - Booleans returned from
intfunctions (14 tests):SessionHandlerInterface::gc()implementations returnedtrueinstead of the number of deleted sessions (13 tests, most of which only emit the deprecation when garbage collection randomly runs, on 1% of requests by default), and the get hook of anintproperty returned the result ofisset(). - Booleans for other
intparameters (3 tests):array_filter($array, $callback, true)instead ofARRAY_FILTER_USE_BOTH, which happens to be1,falsepassed to anintvariadic parameter, and thetruereturned bytouch()passed todate()as the timestamp, which printed a date in 1970 instead of the file's modification time. falsepassed as a database parameter (1 test):PDOStatement::execute()binds every value as a string, so a user-defined SQLite function received""for itsboolparameter. The test now binds the value withPDO::PARAM_BOOL, which passes it as the integer0or1.
The test runner itself had the same kind of bug. When no php.ini was loaded, it printed realpath(get_cfg_var("cfg_file_path")) as the loaded ini file. get_cfg_var() returned false, which became "", causing the runner to incorrectly print the current directory returned by realpath('').
Symfony test suite
Of the roughly 73,000 tests which ran, 269 (0.4%) emitted the new deprecation. The deprecations come from 26 distinct causes: 12 bugs and 14 intentional conversions.
The bugs which the deprecation surfaced:
- Wrong output (2 causes): a value-less parameter is turned into a parameter with the value
1.AcceptHeaderItem::fromString('text/html;flowed')parsesflowedastrue, butsetAttribute()takes astring, so the attribute is stored as"1". Converting the item back to a string then givestext/html; flowed=1instead oftext/html; flowed, andgetAttribute('flowed')returns"1"instead oftrue. Likewise,(string) new ArrayInput(['--verbose' => true])passestruetoescapeToken(string)and gives--verbose=1instead of the value-less option--verbose. - Failure sentinels passed on (3 causes):
falsefromparse_url()returned from a?stringfunction in BrowserKit, fromftell()on a pipe assigned to anintproperty in HttpClient, and fromstrtok()passed totrim()in the OAuth2 token handler. falseas a default or “none” value for astringparameter (2 causes):XmlUtils::phpize($attribute ?? false)in the Validator XML loader, and the FormMoneyTypepassing itscurrency: falseoption to a?stringparameter.- Mistakes in tests (5 causes): a test passed a 4th positional argument which was removed from
TaggedIteratorArgument::__construct(), so'getPriority'became the$excludeargument and was coerced totrue, and the test no longer checks what its name says. Other tests passed'true'toDefinition::setPublic(bool)(3 tests),falseto?stringparameters of a test helper andExecutableFinder::find(), and'hash'to a?boolconstructor parameter.
The other 14 causes are intentional, and three of them affect the most tests. NumberToLocalizedStringTransformer passes its bool grouping option to NumberFormatter::setAttribute(), which takes int|float (152 tests). ResourceCheckerConfigCache::hasResourceCheckers(): bool returns a count(), which is deprecated when there are 2 or more checkers (46 tests). The HTTP cache stores the ESI onerror flag by concatenating a boolean into a string, then passes the resulting "1" or "" back to a bool parameter (13 tests). The other intentional causes are a bitmask result returned from a bool function, three booleans passed to string or int parameters, an unresolved environment variable placeholder passed to a ?bool parameter in a test container, and tests which pass wrong scalar types on purpose, one of which documents that the JSON value "off" becomes true for a bool constructor parameter. The migration guide covers each of these.
The analysis has gaps. Tests in the integration, network, tty, and benchmark groups were excluded, as in Symfony's CI. PHP was built with the openssl, mbstring, intl, curl, fileinfo, sqlite3, pdo_sqlite, sodium, xsl, gmp, ftp, ffi, ldap, and zip extensions, but about 1,500 tests were skipped, mostly because they require PECL extensions such as APCu, AMQP, and Redis, which could not be loaded into the php-src development build, or Unix-only features such as pcntl.
Laravel test suite
Of the roughly 16,600 tests which ran, 96 (0.6%) emitted the new deprecation.
The deprecations come from 14 distinct causes, 10 of which are bugs. 69 of the affected tests go through a single bug in a dependency: the AWS SDK's recursion detection middleware passes getenv('_X_AMZN_TRACE_ID') to str_replace(), which is false whenever the variable isn't set. Two more causes are the Symfony ArrayInput and AcceptHeaderItem bugs described above.
The bugs in Laravel itself:
- Failure sentinels passed on (3 causes):
strlen(base64_decode($payload['iv'], true))inEncrypter, where invalid base64 givesfalse; the JSON test assertions passinggetContent()tojson_decode(), which isfalsefor a streamed response; and thedatevalidation rule passing the parts returned bydate_parse()tocheckdate(), which arefalsewhen missing. - Mistakes in tests (4 causes): 9 tests construct mocks of Symfony's
UploadedFilewith[__FILE__, false], the arguments of its parent classFile, whose second parameter isbool $checkPath. ForUploadedFile, the second parameter isstring $originalName, so the mocks get an empty original filename. The reverse happened in another test, which passedUploadedFilearguments tonew File(...), so''became$checkPath. A PDO test double returnedtruefromexec(), which returnsint|false, and a test set an environment variable totruerather than a string.
The 4 intentional causes are helpers which pass values of mixed types to string functions (Str::lower() when converting validation rule values, and str_starts_with() on the extra conditions of the exists/unique rules, which can be booleans), a test of object_get() with a false key, and a test which creates a response with false content.
The analysis has gaps. The gd extension was enabled in addition to those used for Symfony, but about 730 tests were skipped, mostly because they require the redis, imagick, or memcached extensions, a database other than SQLite, or Linux or macOS, and about 160 failed with errors unrelated to the deprecation, mostly because the tables of the database cache driver were missing.
Comparison with the 2025 proposal
The 2025 proposal also deprecated int 0/1 and string "0"/"1" to bool. To measure the difference, the Symfony and Laravel test suites were run again with a temporary notice for these conversions:
| Test suite | Places (this RFC) | New places added by the 2025 proposal | Notices (this RFC) | Notices added by the 2025 proposal |
|---|---|---|---|---|
| Symfony | 26 | 21 | 714 | 59,929 |
| Laravel | 14 | 2 | 137 | 744 |
In Symfony, the 2025 proposal would have nearly doubled the number of places to fix, and the new places are in far more frequently executed code. 18 of the 21 return a preg_match() result from a bool function or pass one to a bool parameter, in code such as request path and host matching, MIME header encoding, and terminal key parsing. Each new place emitted a median of 247 notices during the test run, and the busiest one, a numeric string check in the JsonPath component, emitted 29,929 on its own, while the places affected by this RFC emitted a median of 2 notices each. The other 3 new places return or pass a bitmask result, or pass a "0" string from an environment variable. None of the new places are bugs. The 2025 proposal would also have deprecated more values at 4 places which this RFC already affects, such as a count() of 0 or 1 in addition to 2 or more.
In Laravel, the 2025 proposal would have added only 2 places, both preg_match() results in Symfony components, but they emitted more than 5 times as many notices as all of this RFC's deprecations.
In php-src, the 2025 proposal would have affected 39 more tests on a local Windows build (it was not measured in CI), most of them passing 0 or 1 to bool parameters of internal functions.
Database values are underrepresented in these numbers, since Symfony's integration tests were excluded and Laravel's database tests could not connect to a server.
References
- RFC: Saner numeric strings (PHP 8.0)
- RFC: Deprecate implicit non-integer-compatible float to int conversions (PHP 8.1)
- PHP manual: Type Juggling
- PHP manual: Strict and coercive typing
- PHP manual: Migrating from PHP 8.4.x to PHP 8.5.x -- Warnings related to cast
- PHP manual: FILTER_VALIDATE_BOOLEAN
- RFC: Coercive Types for Function Arguments (2015), which also proposed rejecting
floattobool - Stricter implicit boolean coercions (2022): discussion thread, voting thread
- Deprecate type juggling to and from bool type within the function type juggling context (2025): discussion thread
Rejected Features
- Change the meaning of
"false","off", or"no"tofalse. This would be a much larger backward-compatibility break, and would replace one silent behavior with another. Strings like this should instead be handled explicitly, e.g. withfilter_var($value, FILTER_VALIDATE_BOOLEAN)or$value === 'yes'.
Changelog
- 2026-11-29: Initial proposal.
- 2026-11-29 (v1.1): Clarified the promotion to
TypeErrorin the next major version, and why""toboolis deprecated.