Bug: [Model] Limitation in Boolean Support (true/false) in update()
/save()
/insert()
#9197
Labels
bug
Verified issues on the current code behavior or pull requests that will fix them
PHP Version
8.3
CodeIgniter4 Version
v4.5.4
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
Currently, CodeIgniter 4 does not support boolean values (
true
andfalse
) in models due to restrictions in the PHPStan typing declaration (@phpstan-type row_array
).CodeIgniter4/system/BaseModel.php
Line 50 in 153922e
This definition only allows
int
,float
,null
,string
, andobject
types, effectively preventing boolean values from being used in database operations.This issue is particularly problematic because certain database drivers natively support boolean values, and they should be allowed for use directly.
Database Driver Details
TINYINT(1)
true
/false
(1/0)BOOLEAN
true
/false
BIT
true
/false
(1/0)INTEGER
NUMBER
Steps to Reproduce
To address this limitation and allow boolean values, it is suggested to:
true
andfalse
) for all supported databases.* @phpstan-type row_array array<int|string, float|int|null|object|string|bool>
true
to 1 andfalse
to 0.Example Code for Handling Boolean Conversion
These changes will ensure better compatibility with all database drivers, allowing proper handling of boolean values in databases that do not natively support them.
Expected Output
Manually casting boolean values is a workaround and places unnecessary burden on developers. CodeIgniter 4 should handle these conversions internally, especially given that:
Many database drivers natively support boolean values (true and false).
The framework should abstract away such differences, allowing developers to focus on business logic rather than database-specific nuances.
In conclusion, while manual casting (e.g., (int)false OR 1/0) solves the problem for now, this limitation should not exist, as proper support for boolean values will make the framework more robust and user-friendly.
Anything else?
No response
The text was updated successfully, but these errors were encountered: