Skip to content

Commit f7750a6

Browse files
authored
fix: Fix conflicting humbug_phpscoper_expose_class class declaration (#811)
Closes #809
1 parent fa89963 commit f7750a6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/Autoload/ScoperAutoloadGenerator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ final class ScoperAutoloadGenerator
4242
EOF;
4343

4444
private const EXPOSE_CLASS_DECLARATION = <<<'PHP'
45-
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
46-
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
47-
spl_autoload_call($prefixed);
45+
if (!function_exists('humbug_phpscoper_expose_class')) {
46+
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
47+
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
48+
spl_autoload_call($prefixed);
49+
}
4850
}
4951
}
5052
PHP;

tests/Autoload/ScoperAutoloadGeneratorTest.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ public static function provideRegistry(): iterable
279279
280280
// Class aliases. For more information see:
281281
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
282-
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
283-
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
284-
spl_autoload_call($prefixed);
282+
if (!function_exists('humbug_phpscoper_expose_class')) {
283+
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
284+
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
285+
spl_autoload_call($prefixed);
286+
}
285287
}
286288
}
287289
humbug_phpscoper_expose_class('A\Foo', 'Humbug\A\Foo');
@@ -323,9 +325,11 @@ function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void
323325
324326
// Class aliases. For more information see:
325327
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
326-
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
327-
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
328-
spl_autoload_call($prefixed);
328+
if (!function_exists('humbug_phpscoper_expose_class')) {
329+
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
330+
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
331+
spl_autoload_call($prefixed);
332+
}
329333
}
330334
}
331335
humbug_phpscoper_expose_class('Foo', 'Humbug\Foo');
@@ -376,9 +380,11 @@ function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void
376380
// Class aliases. For more information see:
377381
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
378382
namespace {
379-
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
380-
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
381-
spl_autoload_call($prefixed);
383+
if (!function_exists('humbug_phpscoper_expose_class')) {
384+
function humbug_phpscoper_expose_class(string $exposed, string $prefixed): void {
385+
if (!class_exists($exposed, false) && !interface_exists($exposed, false) && !trait_exists($exposed, false)) {
386+
spl_autoload_call($prefixed);
387+
}
382388
}
383389
}
384390
humbug_phpscoper_expose_class('A\Foo', 'Humbug\A\Foo');

0 commit comments

Comments
 (0)