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

Hi, how would I be able to fix this error? The current code is below but I’m not sure how to fix this deprecation error:

foreach ( $res as $row ) {
		$user = $this->getOption( 'user' );
		if ( $user ) {
			$nameIsValid = User::newFromName( $user )->getId();
			$name = $this->importPrefix . $user;
			if ( strpos( $row->rev_user_text, $this->importPrefix ) === 0 ) {
				if ( $nameIsValid !== 0 && $row->rev_user_text === $name ) {
					$this->assignEdit( $name );
				}
			}
		} else {
			$user = $row->rev_user_text;
			$nameIsValid = User::newFromName( str_replace( $this->importPrefix, '', $user ) );
			if ( strpos( $user, $this->importPrefix ) === 0 ) {
				if ( $nameIsValid && $user ) {
					$this->assignEdit( $user );
				}
			}
		}
	}
}

The documentation gives more information on this. In your code, $this->importPrefix is not a string. strpos handles this by converting the value to an integer and finding the corresponding character, using similar logic to the chr() function. If this is what you want, you can explicitly call chr() to make the error go away:

strpos( $row->rev_user_text, chr($this->importPrefix))

If you expect $this->importPrefix to be a string, then you need to look at why it isn’t. It may be the value is being set as an integer when you meant it to be a string composed of numeric digits: 4 versus "4" for example.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service