CodeIgniter4: Bug: "integer" validation rule 500 error
PHP Version
8.1
CodeIgniter4 Version
4.2.5
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
The validation rule “integer” fail as 500 error as below
{
"title": "TypeError",
"type": "TypeError",
"code": 500,
"message": "CodeIgniter\\Validation\\FormatRules::integer(): Argument #1 ($str) must be of type ?string, array given, called in /var/www/src/system/Validation/Validation.php on line 314",
"file": "/var/www/src/system/Validation/FormatRules.php",
"line": 132,
"trace": [
{
"file": "/var/www/src/system/Validation/Validation.php",
"line": 314,
"function": "integer",
"class": "CodeIgniter\\Validation\\FormatRules",
"type": "->",
"args": [
[],
null
]
},
{
"file": "/var/www/src/system/Validation/Validation.php",
"line": 163,
"function": "processRules",
"class": "CodeIgniter\\Validation\\Validation",
"type": "->",
...
That validation allows string numeric (not integer) as well
Steps to Reproduce
Validation rule used
protected $validationRules = [
'integerAcceptsStringNumeric' => 'integer',
'integerArrayError' => 'integer',
];
Data to validate
$data = [
'integerAcceptsStringNumeric' => '1',
'integerArrayError' => [],
];
Expected Output
Validation fail and return 400 if the value is not an integer
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (14 by maintainers)
@shishamo I sent a PR: #6492
It is just a bug.
1
should be passed without errors.