1.5.2 & PHP 8.1: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated

edited August 2022 in Bug Reports

Hello,

With PHP 8.1 I was experiencing a PHP error (see below)

Maybe it is because I was getting data from an old database ?

Anyway, I found a fix :
in file : \fuel\modules\fuel\core\MY_DB_mysqli_driver.php
I added the line (number 189) :
if ($max_length!=NULL)

so that in the end :

            if ($type == 'float')
            {
                if (is_array($max_length))
                {
                    $max_length = current($max_length);
                }

                if ($max_length!=NULL)
                    if (strpos($max_length, ',') !== FALSE)
                    {
                        $maxes = explode(',', $max_length);
                        $max_length = 0;
                        foreach($maxes as $max)
                        {
                            $max_length += (int) $max;
                        }
                    }
            }

Here is the error :

A PHP Error was encountered
Severity: 8192

Message: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated

Filename: core/MY_DB_mysqli_driver.php

Line Number: 189
Sign In or Register to comment.