From 9273aa7e7d1d64e98987174d0f2e7abd875a3cad Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 26 Jan 2025 19:04:02 +0100 Subject: [PATCH 1/3] Fix PHP 8.4 implicit nullability deprecation (take 2) This re-does @xabbuh's commit 7b307a92373542a10f1265df420d424ea4d51062, in a PHP >= 5.1 backwards-compatible way. --- Parsedown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 1b9d6d5bc..231894a6e 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -712,9 +712,9 @@ protected function blockRule($Line) # # Setext - protected function blockSetextHeader($Line, array $Block = null) + protected function blockSetextHeader($Line, array $Block = array()) { - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) + if (empty($Block) or isset($Block['type']) or isset($Block['interrupted'])) { return; } @@ -850,9 +850,9 @@ protected function blockReference($Line) # # Table - protected function blockTable($Line, array $Block = null) + protected function blockTable($Line, array $Block = array()) { - if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) + if (empty($Block) or isset($Block['type']) or isset($Block['interrupted'])) { return; } From e431ecd3a95948c9f212e2a76fdfd5808e99af39 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Mon, 27 Jan 2025 01:59:19 +0100 Subject: [PATCH 2/3] Fix broken CI builds Changing the $Block parameter's default value from null to array() caused the PHPUnit tests to fail with "Argument #2 ($Block) must be of type array, null given". Initializing $CurrentBlock variable in lines() method to array() instead of null, and change subsequent tests from isset() to !empty(). Also change blockCode() method signature, which was missed in previous commit. --- Parsedown.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 231894a6e..debba4401 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -143,13 +143,13 @@ function setSafeMode($safeMode) protected function lines(array $lines) { - $CurrentBlock = null; + $CurrentBlock = []; foreach ($lines as $line) { if (chop($line) === '') { - if (isset($CurrentBlock)) + if (!empty($CurrentBlock)) { $CurrentBlock['interrupted'] = true; } @@ -255,7 +255,7 @@ protected function lines(array $lines) # ~ - if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) + if (!empty($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) { $CurrentBlock['element']['text'] .= "\n".$text; } @@ -317,9 +317,9 @@ protected function isBlockCompletable($Type) # # Code - protected function blockCode($Line, $Block = null) + protected function blockCode($Line, $Block = array()) { - if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) + if (!empty($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) { return; } From f5202399a8381792cab3cdcc1b87955581316569 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Mon, 27 Jan 2025 02:08:29 +0100 Subject: [PATCH 3/3] Short array syntax is only available since PHP 5.4 --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index debba4401..64e8a1165 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -143,7 +143,7 @@ function setSafeMode($safeMode) protected function lines(array $lines) { - $CurrentBlock = []; + $CurrentBlock = array(); foreach ($lines as $line) {