Skip to content

Commit 29a00f5

Browse files
author
Sijun Zhu
committed
make special case for __halt_compiler()
1 parent f032387 commit 29a00f5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,24 @@ public function register()
7474

7575
// If we are not pattern matching, we need to work out what
7676
// tokens to listen for.
77-
$tokens = [];
77+
$string = '<?php ';
78+
$hasHaltCompiler = false;
7879
foreach ($this->forbiddenFunctionNames as $name) {
79-
$token = token_get_all(sprintf('<?php %s();', $name));
80-
array_shift($token);
81-
$tokens = array_merge($tokens, $token);
80+
if ($name === '__halt_compiler') {
81+
$hasHaltCompiler = true;
82+
} else {
83+
$string .= $name.'();';
84+
}
85+
}
86+
87+
if ($hasHaltCompiler) {
88+
$string .= '__halt_compiler();';
8289
}
8390

8491
$register = [];
8592

93+
$tokens = token_get_all($string);
94+
array_shift($tokens);
8695
foreach ($tokens as $token) {
8796
if (is_array($token) === true) {
8897
$register[] = $token[0];

0 commit comments

Comments
 (0)