Smart Search: utf8_strpos: Offset must be an integer #10303
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Under some circumstances a search for a word can result in a "PHP Fatal error: utf8_strpos: Offset must be an integer". This is because the floor function used to calculate the offset can sometimes return a float rather than an int.
Summary of Changes
The return value from the floor is now cast to an int to make sure that the offset (the 3rd argument) passed to JString::strpos, which becomes the offset argument to utf8_strpos, is always an int.
Testing Instructions
This may be tricky to replicate but this is how I encountered the problem in the first place...
This should throw the error on one of the search results. For me it happened on "Modules" and "Sample Sites".
Apply this PR and repeat the test.