Page 1 of 1

explode(): Passing null to parameter #2 ($string) of type string is deprecated

Posted: Tue Jul 30, 2024 2:37 pm
by buhuhu

Hello,

I have a table with save file name by ID like this:

$NewFiles = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $rsnew["FilesAll"]);
$nextid = ExecuteScalar("SELECT COALESCE(MAX(id),0) +1 CNT FROM tblDocs") ;
$FileCount = count($NewFiles);

  if (trim($NewFiles[0])=='') return TRUE ;
  
for ($i = 0; $i < $FileCount; $i++) {
	if ( trim($NewFiles[$i]) != '') {
		$files = $NewFiles[$i];
		$file_extension = substr(strtolower(strrchr($files, ".")), 1);
		$files = $nextid.   "-files" . "-" .($i + 1). "." . $file_extension;
		$NewFiles[$i] = $files;
	}
}

$sFileName = implode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $NewFiles);
$rsnew['FilesAll'] = $sFileName;

Now error is:

explode(): Passing null to parameter #2 ($string) of type string is deprecated

Can fix that ?

(v2024)

Regards


Re: migrate to v2024

Posted: Tue Jul 30, 2024 3:03 pm
by mobhar

In which server event did you put that code?


Re: explode(): Passing null to parameter #2 ($string) of type string is deprecated

Posted: Tue Jul 30, 2024 3:37 pm
by arbei

buhuhu wrote:

$NewFiles = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $rsnew["FilesAll"]);

Your $rsnew["FilesAll"] is null, you should check and handle null. You may google the PHP error message for more info about the deprecation since PHP 8.1.