Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future

Tags:

I have this error appear in php 7.3

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

The line is :

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

It seems it come from this code : strpos('_', $this->Category->getPath()

$this->Category->getPath() can return this value for example :

int(8)   string(3) "8_9" 
like image 727
Tristan Avatar asked May 18 '19 17:05

Tristan


People also ask

Is Strpos deprecated?

This behavior is deprecated as of PHP 7.3. 0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to chr() should be performed.

What is the strpos () function used for?

The strpos() function finds the position of the first occurrence of a string inside another string.


1 Answers

This worked for me

$suffix = strval($this->config->item('controller_suffix')); $pos = !empty($suffix) ? strpos($class, $suffix) : FALSE; if ($pos === FALSE) {     $class .= $suffix; } parent::set_class($class); 
like image 141
Harish Chandra Kharel Avatar answered Oct 27 '22 06:10

Harish Chandra Kharel