# [RFC] Deprecate lossy conversions to and from bool

- Thread: https://externals.io/message/133249
- Original archive: https://news-web.php.net/php.internals/133249
- Started by Theodore Brown on 2026-11-29T14:33:01+00:00
- Messages: 2
- RFC: Deprecate lossy conversions to and from bool (Under discussion) — https://externals.io/rfc/deprecate-lossy-bool-conversions.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #133249 — Theodore Brown — 2026-11-29T14:33:01+00:00

URL: https://externals.io/message/133249#133249

Hello Internals,

I've been planning this RFC for quite some time, and during the Thanksgiving break I finally had time to finish it:

https://wiki.php.net/rfc/deprecate-lossy-bool-conversions


Looking forward to your feedback,

Theodore Brown

---

## #133255 — Rowan Tommins [IMSoP] — 2026-11-29T17:34:30+00:00

URL: https://externals.io/message/133249#133255 · In reply to: #133249

> Hello Internals,
>
> I've been planning this RFC for quite some time, and during the Thanksgiving break I finally had time to finish it:
>
> https://wiki.php.net/rfc/deprecate-lossy-bool-conversions


Hi Theodore,

Thanks for a very well-written RFC; I particularly appreciate the survey 
of previous proposals and discussion of how this proposal differs.

I think I am broadly in favour, but have two comments:


Firstly, I am not a fan of open-ended deprecations, and read most of the 
RFC thinking this was one. There is only one mention of "... and promote 
to a TypeError in the next major release (PHP 9.0)".

I think I agree with that timeline, but it should probably be mentioned 
elsewhere as well - e.g. in the Proposal section, and in the Voting 
description - so that people are clear that they are voting for the 
future removal, not just the initial deprecation.


Secondly, I'm not totally sold on the choice of accepted strings. In the 
FAQ you say this:


> "Are the 0/1 and "0"/"1" values arbitrary?"
>
> No. They are the canonical encoding of booleans used by database 
> columns, query strings, and many APIs.

This claim feels a bit strong to me. PostgreSQL canonically encodes 
booleans as 'f' and 't'; a lot of other databases (e.g. MySQL, SQLite, 
SQL Server, Oracle) don't have true booleans, and use integer 0 and 1 by 
convention. HTML defaults the value of a selected checkbox to 'on' and 
an unselected one is left undefined.

Perhaps more importantly, PHP itself produces '' not '0' when casting or 
coercing a boolean false to string. Under the proposal, this code would 
be rejected rather than printing bool(false):

function wants_bool(bool $val) {
    var_dump($val);
}
function wants_string(string $val) {
     wants_bool($val);
}
wants_string(false);

I think accepting the "round-trippable" values should be the minimum, so 
0 and '' for false, and 1 and '1' for true. I'd be happy accepting '0' 
as well, because it is already special-cased to false rather than 
falling into the catch-all "non-empty string" case.


Thanks again for your work on the RFC.

-- 
Rowan Tommins
[IMSoP]
