1.2.1672. 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.1672.2. Connex PHP features¶
1.2.1672.2.1. Suggestions¶
Add a cast to make the data string
Test the data to be a string before usage
1.2.1672.2.2. Specs¶
Short name |
Php/StrposWithIntegers |
Rulesets |
|
Exakat since |
2.5.2 |
PHP Version |
With PHP 8.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Changed Behavior |
PHP 8.0 - More |
Precision |
High |
Available in |