Repository: humbug/php-scoper (php)

Issue:
scoper-autoload.php doesn't support PHP 5.6 (again)
## Bug report

| Question    | Answer
| ------------| ---------------
| PHP-Scoper version | 0.18.7
| PHP version | 5.6
| Platform with version | all
| Github Repo | -

This is a followup to #842. I found another thing in `scoper-autoload.php` that is incompatible with PHP 5.6 - the `??` operator. PR incoming.

See the error here: https://github.com/skaut/skaut-google-drive-gallery/actions/runs/8883783876/job/24391429247?pr=2632


Pull request:
Fixed scoper-autoload.php PHP 5.6 incompatibility
Closes #1023


Patch:
diff --git a/src/Autoload/ScoperAutoloadGenerator.php b/src/Autoload/ScoperAutoloadGenerator.php
index 0dc62b1..b4c9206 100644
--- a/src/Autoload/ScoperAutoloadGenerator.php
+++ b/src/Autoload/ScoperAutoloadGenerator.php
@@ -103,7 +103,7 @@ final class ScoperAutoloadGenerator
                 namespace {
                     \$loader = (static function () {
                         // Backup the autoloaded Composer files
-                        \$existingComposerAutoloadFiles = \$GLOBALS['__composer_autoload_files'] ?? [];
+                        \$existingComposerAutoloadFiles = isset(\$GLOBALS['__composer_autoload_files']) ? \$GLOBALS['__composer_autoload_files'] : [];
 
                         \$loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available
@@ -135,7 +135,7 @@ final class ScoperAutoloadGenerator
 
                 \$loader = (static function () {
                     // Backup the autoloaded Composer files
-                    \$existingComposerAutoloadFiles = \$GLOBALS['__composer_autoload_files'] ?? [];
+                    \$existingComposerAutoloadFiles = isset(\$GLOBALS['__composer_autoload_files']) ? \$GLOBALS['__composer_autoload_files'] : [];
 
                     \$loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available


Test patch:
diff --git a/tests/Autoload/AutoloadDumperTest.php b/tests/Autoload/AutoloadDumperTest.php
index eb05957..fda20e1 100644
--- a/tests/Autoload/AutoloadDumperTest.php
+++ b/tests/Autoload/AutoloadDumperTest.php
@@ -153,7 +153,7 @@ final class AutoloadDumperTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     // @generated by Humbug Box
 
@@ -252,7 +252,7 @@ final class AutoloadDumperTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     // @generated by Humbug Box
 
@@ -350,7 +350,7 @@ final class AutoloadDumperTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         // @generated by Humbug Box
 
diff --git a/tests/Autoload/ScoperAutoloadGeneratorTest.php b/tests/Autoload/ScoperAutoloadGeneratorTest.php
index a3cc75a..7fa4b91 100644
--- a/tests/Autoload/ScoperAutoloadGeneratorTest.php
+++ b/tests/Autoload/ScoperAutoloadGeneratorTest.php
@@ -48,7 +48,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -79,7 +79,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -115,7 +115,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -156,7 +156,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -199,7 +199,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         $loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available
@@ -251,7 +251,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         $loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available
@@ -303,7 +303,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         $loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available
@@ -352,7 +352,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -399,7 +399,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -454,7 +454,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         $loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available
@@ -522,7 +522,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
 
                 $loader = (static function () {
                     // Backup the autoloaded Composer files
-                    $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                    $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                     $loader = require_once __DIR__.'/autoload.php';
                     // Ensure InstalledVersions is available
@@ -564,7 +564,7 @@ class ScoperAutoloadGeneratorTest extends TestCase
                 namespace {
                     $loader = (static function () {
                         // Backup the autoloaded Composer files
-                        $existingComposerAutoloadFiles = $GLOBALS['__composer_autoload_files'] ?? [];
+                        $existingComposerAutoloadFiles = isset($GLOBALS['__composer_autoload_files']) ? $GLOBALS['__composer_autoload_files'] : [];
 
                         $loader = require_once __DIR__.'/autoload.php';
                         // Ensure InstalledVersions is available