【发布时间】:2018-10-09 21:06:00
【问题描述】:
代码中出现以下错误的原因是什么? 第一次运行没有问题,但第二次出现“遇到非数值”错误:
public function checkName(string $name, string $path, string $extension, int $num)
{
if (Storage::exists("$path/$name"))
{
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $name);
if ($num > 1)
$withoutExt = str_replace('_'.$num-1, '_'.$num, $withoutExt);
else
$withoutExt = $withoutExt . '_'.$num;
$newName = "$withoutExt.$extension";
if (Storage::exists("$path/$newName")) {
return $this->checkName($newName, $path, $extension, $num+1);
}
else
return $newName;
}
return $name;
}
$fileNameSave = (new Attachment)->checkName($fileName, $filePath, $file->getClientOriginalExtension(), 1);
exception: "ErrorException"
line: 84
message: "A non-numeric value encountered"
【问题讨论】:
-
第84行是哪一个?
-
$withoutExt = str_replace(''.$num-1, ''.$num, $withoutExt);在第 84 行
标签: php laravel php-7 laravel-5.7