CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

CI3 and PHP8.1(ctype_digit(): Argument of type int will be interpreted as string in the future)

Open Obata2024 opened this issue 1 year ago • 5 comments

When trying to use PostgreSQL under the given conditions, the following error occurs:

A PHP Error was encountered Severity: 8192

Message: ctype_digit(): Argument of type int will be interpreted as string in the future

Filename: postgre/postgre_driver.php

Line Number: 98

Should I modify the postgre/postgre_driver.php file to resolve this? If it’s acceptable, I can submit a PR.

Also, has anyone resolved the same issue using an override? I attempted to create a custom class under the application/core directory to override it, but this error still persists.

Obata2024 avatar Jun 26 '24 07:06 Obata2024

Looks to me that the ctype part of that if statement should just be removed. As far as I can see so far none of the other drivers check anything other than that the value isn't empty before using it.

jamieburchell avatar Jun 30 '24 22:06 jamieburchell

Removing the check might have unintended consequences so a better approach would be to simply cast the variable as a string which is done pretty much everywhere else in the framework.

Change line 98 in the file to read:

if ( ! empty($this->port) && ctype_digit((string) $this->port))

daveherman71 avatar Jul 11 '24 14:07 daveherman71

Removing the check might have unintended consequences so a better approach would be to simply cast the variable as a string which is done pretty much everywhere else in the framework.

It's inconsistently checked in each database driver. Most just check if the port is not empty. In this case, it's just to find out if the port number is not empty. If casting to a string, this should also be applied elsewhere such as here and here.

jamieburchell avatar Jul 11 '24 14:07 jamieburchell

The thing is, in some of these cases the variable is expected to be a string and not an int, for example in the valid_url function. The lack of type hinting on the method parameters is biting us here.

Either way, the simplest fix here is casting. I'll open a PR later and add it to my fork.

jamieburchell avatar Jul 15 '24 06:07 jamieburchell