已弃用:strpos():非弦针将来将被解释为字符串

php
2022-08-30 17:40:17

我在 php 7.3 中出现了此错误

已弃用:strpos():非弦针将来将被解释为字符串。使用显式 chr() 调用来保留当前行为

该行是:

if ($this->Category->getPath() && strpos('_', $this->Category->getPath())) {

它似乎来自这个代码:strpos('_', $this->Category->getPath()

$this->Category->getPath()可以返回此值,例如:

int(8)  
string(3) "8_9"

答案 1

这对我有用

$suffix = strval($this->config->item('controller_suffix'));
$pos = !empty($suffix) ? strpos($class, $suffix) : FALSE;
if ($pos === FALSE)
{
    $class .= $suffix;
}
parent::set_class($class);

答案 2

您所要做的就是传入一个字符串作为 strpos 的参数。

strpos('_', strval($this->Category->getPath()))

或者,确保 返回字符串而不是混合类型。Category->getPath()


推荐