Bug #81002 [Com]: Booleans are cast to integers when inserting records

From: Date: Mon, 03 May 2021 10:44:16 +0000
Subject: Bug #81002 [Com]: Booleans are cast to integers when inserting records
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233637@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81002&edit=1

 ID:                 81002
 Comment by:         appmaker at nibnut dot com
 Reported by:        jeroen dot vanoort at webparking dot nl
 Summary:            Booleans are cast to integers when inserting records
 Status:             Closed
 Type:               Bug
 Package:            PDO PgSQL
 Operating System:   Alpine
 PHP Version:        8.0.5
 Assigned To:        mbeccati
 Block user comment: N
 Private report:     N

 New Comment:

The bug also happens in php7.4.18... Any way to get the fix in there too please?


Previous Comments:
------------------------------------------------------------------------
[2021-05-03 08:48:44] 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-04-30 11:14:25] cmb@php.net

This might be due the fix for bug #80892 which has recently been
reverted.

------------------------------------------------------------------------
[2021-04-30 11:04:31] 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))


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81002&edit=1


Thread (7 messages)

« previous php.bugs (#233637) next »