php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81002 Booleans are cast to integers when inserting records
Submitted: 2021-04-30 11:04 UTC Modified: 2021-05-03 10:46 UTC
Votes:7
Avg. Score:4.7 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:7 (100.0%)
Same OS:2 (28.6%)
From: jeroen dot vanoort at webparking dot nl Assigned: mbeccati (profile)
Status: Closed Package: PDO PgSQL
PHP Version: 8.0.5 OS: Alpine
Private report: No CVE-ID: None
 [2021-04-30 11:04 UTC] jeroen dot vanoort at webparking dot nl
Description:
------------
It seems that, since using 8.0.5, booleans are cast to integers when inserting records into a PostgreSQL database table. This causes PostgreSQL to throw an exception.

I use Laravel to do this, so it's not trivial for me to create a test script that's only PHP. However, I did want to report this as it seems to be an unintentional breaking change.

How did I determine this isn't related to Laravel or PostgreSQL?
I tested my project with the php:8.0.3-fpm-alpine and php:8.0.3-fpm-alpine docker images. 8.0.3 works fine, 8.0.5 gives me the error below. I did not change the Laravel version, nor did I change the PostgreSQL version.

The boolean true seems to have been casted to an integer in the SQL shown in the error message.

Test script:
---------------
ProductCategory::create([
    'name' => 'FooBar',
    'is_active' => true,
]);

ProductCategory is a Laravel model.

Expected result:
----------------
The record is added without errors or warnings.

Actual result:
--------------
Illuminate\Database\QueryException: SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  column "is_active" is of type boolean but expression is of type integer
LINE 1: ...e", "id", "updated_at", "created_at") values ($1, $2, $3, $4...
                                                             ^
HINT:  You will need to rewrite or cast the expression. (SQL: insert into "product_categories" ("name", "is_active", "id", "updated_at", "created_at") values (FooBar, 1, 1eba993a-28f3-6596-9455-7e5293aad700, 2021-04-30 11:08:31, 2021-04-30 11:08:31))

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-30 11:14 UTC] cmb@php.net
This might be due the fix for bug #80892 which has recently been
reverted.
 [2021-05-03 08:48 UTC] mbeccati@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: mbeccati
 [2021-05-03 08:48 UTC] mbeccati@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Confirmed, this was caused by the fix for #80892, which has now been reverted.
 [2021-05-03 10:44 UTC] appmaker at nibnut dot com
The bug also happens in php7.4.18... Any way to get the fix in there too please?
 [2021-05-03 10:46 UTC] mbeccati@php.net
Yes, the official 8.0.6 and 7.4.19 will contain the revert/fix.
 [2021-05-06 13:10 UTC] josh at kimmel dot com
This still seems to be an issue in 8.0.6
 [2021-05-06 20:55 UTC] valentin dot funk at gmail dot com
Thank you very much for this fix! 
I was very confused that some unit tests were failing since a few days. PHP 7.4.19 (together with PostgreSQL 11.11_2; both installed via Homebrew) now runs my application again on a MacBook Air M1 (Apple Silicon).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Dec 06 14:03:34 2021 UTC