1.2.1647. strpos() With Integers

strpos() used to accept integer as second argument, and turn them into their ASCII equivalent. This was deprecated in PHP 7.x, and dropped in 8.0.

It is recommended to use casting to ensure the variable is actually strings, and strpos() behaves as expected.

<?php

strpos('abc ', 32);
// PHP 8.0+ : false, 32 is not found
// PHP 7.4- : 3, 32 is turned into space, then found

?>

1.2.1647.1. Suggestions

  • Add a cast to make the data string

  • Test the data to be a string before usage

1.2.1647.2. Specs

Short name

Php/StrposWithIntegers

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.5.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Changed Behavior

PHP 8.0 - More

Precision

High

Available in

Entreprise Edition, Exakat Cloud