From 9400c1643596def9325a6a849e3524dbb1f73b83 Mon Sep 17 00:00:00 2001 From: Wim Wisselink Kantoor Date: Thu, 8 Dec 2022 13:39:55 +0100 Subject: [PATCH 1/6] PHP 8.2 deprecation fix: Dynamically call 'parent::__construct()' fix --- src/JS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JS.php b/src/JS.php index a348491..65fe89f 100644 --- a/src/JS.php +++ b/src/JS.php @@ -127,7 +127,7 @@ class JS extends Minify */ public function __construct() { - call_user_func_array(array('parent', '__construct'), func_get_args()); + parent::__construct(func_get_args()); $dataDir = __DIR__ . '/../data/js/'; $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; From eafe9b9527343944385a81f56a86c744f04ad6df Mon Sep 17 00:00:00 2001 From: Wim Wisselink Kantoor Date: Thu, 8 Dec 2022 13:56:21 +0100 Subject: [PATCH 2/6] PHP 8.2 deprecation fix: Dynamically call 'parent::__construct()' with argument count check fix --- src/JS.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/JS.php b/src/JS.php index 65fe89f..a01f45e 100644 --- a/src/JS.php +++ b/src/JS.php @@ -127,7 +127,10 @@ class JS extends Minify */ public function __construct() { - parent::__construct(func_get_args()); + // Can't just call parent::__construct() + if (func_num_args()) { + parent::__construct(func_get_args()); + } $dataDir = __DIR__ . '/../data/js/'; $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; @@ -182,7 +185,7 @@ public function execute($path = null) // clean up leftover `;`s from the combination of multiple scripts $content = ltrim($content, ';'); - $content = (string) substr($content, 0, -1); + $content = (string)substr($content, 0, -1); /* * Earlier, we extracted strings & regular expressions and replaced them @@ -266,7 +269,7 @@ protected function extractRegex() // a regular expression can only be followed by a few operators or some // of the RegExp methods (a `\` followed by a variable or value is // likely part of a division, not a regex) - $keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof'); + $keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof'); $before = '(^|[=:,;\+\-\*\?\/\}\(\{\[&\|!]|' . implode('|', $keywords) . ')\s*'; $propertiesAndMethods = array( // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Properties_2 @@ -474,7 +477,7 @@ protected function stripWhitespace($content) * This will prepare the given array by escaping all characters. * * @param string[] $operators - * @param string $delimiter + * @param string $delimiter * * @return string[] */ @@ -505,7 +508,7 @@ protected function getOperatorsForRegex(array $operators, $delimiter = '/') * This will prepare the given array by escaping all characters. * * @param string[] $keywords - * @param string $delimiter + * @param string $delimiter * * @return string[] */ From 156d5ed81c8759d8f450f7b663094e7d513f2a37 Mon Sep 17 00:00:00 2001 From: Wim Wisselink Kantoor Date: Thu, 8 Dec 2022 14:04:04 +0100 Subject: [PATCH 3/6] Revert auto formatting --- src/JS.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/JS.php b/src/JS.php index a01f45e..7946caf 100644 --- a/src/JS.php +++ b/src/JS.php @@ -185,7 +185,7 @@ public function execute($path = null) // clean up leftover `;`s from the combination of multiple scripts $content = ltrim($content, ';'); - $content = (string)substr($content, 0, -1); + $content = (string) substr($content, 0, -1); /* * Earlier, we extracted strings & regular expressions and replaced them @@ -269,7 +269,7 @@ protected function extractRegex() // a regular expression can only be followed by a few operators or some // of the RegExp methods (a `\` followed by a variable or value is // likely part of a division, not a regex) - $keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof'); + $keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof'); $before = '(^|[=:,;\+\-\*\?\/\}\(\{\[&\|!]|' . implode('|', $keywords) . ')\s*'; $propertiesAndMethods = array( // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Properties_2 @@ -477,7 +477,7 @@ protected function stripWhitespace($content) * This will prepare the given array by escaping all characters. * * @param string[] $operators - * @param string $delimiter + * @param string $delimiter * * @return string[] */ @@ -508,7 +508,7 @@ protected function getOperatorsForRegex(array $operators, $delimiter = '/') * This will prepare the given array by escaping all characters. * * @param string[] $keywords - * @param string $delimiter + * @param string $delimiter * * @return string[] */ From 4e7c673c359aa8b634c9d418c253f5902cdebb0b Mon Sep 17 00:00:00 2001 From: Wim Wisselink Kantoor Date: Thu, 8 Dec 2022 14:20:39 +0100 Subject: [PATCH 4/6] Add PHP 8.2 to test flow. --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d36ec7..725e688 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Test PHP 8.2 + run: make test PHP=8.2 - name: Test PHP 8.1 run: make test PHP=8.1 - name: Test PHP 8.0 From 11c7b047ba4b298816bf837fb0e7e60eea92ef60 Mon Sep 17 00:00:00 2001 From: Wim Wisselink Kantoor Date: Thu, 8 Dec 2022 14:22:38 +0100 Subject: [PATCH 5/6] Update PHP 8.2 test flow to PHP 8.2-rc. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 725e688..4c29142 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Test PHP 8.2 - run: make test PHP=8.2 + run: make test PHP=8.2-rc - name: Test PHP 8.1 run: make test PHP=8.1 - name: Test PHP 8.0 From aa8010c2fa3c26f018874141d36025085754abff Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Fri, 9 Dec 2022 13:54:33 +0100 Subject: [PATCH 6/6] Move back to call_user_func_array This is equivalent, but removes the assumption that parent constructor will also accept a single array val as well as overloading. That assumption is true, but may not always remain true. Frankly, all of this is due for massive refactoring, but that's something for... well, not today, that's for sure! --- src/JS.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/JS.php b/src/JS.php index 7946caf..ac5e98d 100644 --- a/src/JS.php +++ b/src/JS.php @@ -127,10 +127,7 @@ class JS extends Minify */ public function __construct() { - // Can't just call parent::__construct() - if (func_num_args()) { - parent::__construct(func_get_args()); - } + call_user_func_array(array('\\MatthiasMullie\Minify\\Minify', '__construct'), func_get_args()); $dataDir = __DIR__ . '/../data/js/'; $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;