From 9f3f366cf3affbe3325f86ae0e06b81dccb99b09 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Aug 2021 16:49:09 -0700 Subject: [PATCH] Fixes: PHP 8.0: Argument #3 ($offset) must be contained in argument #1 ($haystack) --- src/Psalm/Codebase.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 2fcefc240..9906c6ef4 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -1817,7 +1817,14 @@ class Codebase { $file_contents = substr($file_contents, 0, $offset); - $before_newline_count = strrpos($file_contents, "\n", $offset - strlen($file_contents)); + $offsetLength = $offset - strlen($file_contents); + + //PHP 8.0: Argument #3 ($offset) must be contained in argument #1 ($haystack) + if (($textlen = strlen($file_contents)) < $offsetLength) { + $offsetLength = $textlen; + } + + $before_newline_count = strrpos($file_contents, "\n", $offsetLength); return new Position( substr_count($file_contents, "\n"),