Skip to content

Commit 3dde183

Browse files
authored
fix: Correctly scope spl_autoload_register singule parameter (#887)
1 parent 9cea251 commit 3dde183

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

specs/string-literal/func-arg-spl-auto-register.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
'FQCN string argument' => <<<'PHP'
3939
<?php
4040
41+
spl_autoload_register('sodiumCompatAutoloader');
42+
spl_autoload_register('Sodium\compatAutoloader');
4143
spl_autoload_register(['Swift', 'autoload']);
4244
spl_autoload_register(['\Swift', 'autoload']);
4345
spl_autoload_register(['Humbug\\Swift', 'autoload']);
@@ -51,6 +53,8 @@
5153
5254
namespace Humbug;
5355
56+
\spl_autoload_register('Humbug\\sodiumCompatAutoloader');
57+
\spl_autoload_register('Humbug\\Sodium\\compatAutoloader');
5458
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
5559
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
5660
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
@@ -84,6 +88,23 @@
8488
PHP,
8589
],
8690

91+
'FQCN string argument on exposed function' => [
92+
'expose-functions' => ['sodiumCompatAutoloader'],
93+
'payload' => <<<'PHP'
94+
<?php
95+
96+
spl_autoload_register('sodiumCompatAutoloader');
97+
98+
----
99+
<?php
100+
101+
namespace Humbug;
102+
103+
\spl_autoload_register('Humbug\\sodiumCompatAutoloader');
104+
105+
PHP,
106+
],
107+
87108
'FQCN string argument on class from an excluded namespace' => [
88109
'exclude-namespaces' => [
89110
'Symfony\Component\Yaml',
@@ -110,6 +131,26 @@
110131
PHP,
111132
],
112133

134+
'FQCN string argument on function from an excluded namespace' => [
135+
'exclude-namespaces' => [
136+
'Sodium',
137+
'/^$/',
138+
],
139+
'payload' => <<<'PHP'
140+
<?php
141+
142+
spl_autoload_register('Sodium\CompatAutoloader');
143+
144+
----
145+
<?php
146+
147+
namespace {
148+
\spl_autoload_register('Sodium\\CompatAutoloader');
149+
}
150+
151+
PHP,
152+
],
153+
113154
'FQCN string argument with global functions not exposed' => [
114155
'expose-global-functions' => false,
115156
'payload' => <<<'PHP'

src/PhpParser/NodeVisitor/StringScalarPrefixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ final class StringScalarPrefixer extends NodeVisitorAbstract
8080
'interface_exists',
8181
'is_a',
8282
'is_subclass_of',
83+
'spl_autoload_register',
8384
'trait_exists',
8485
];
8586

0 commit comments

Comments
 (0)