Skip to content

Commit 40b8942

Browse files
authored
Do not prefix internal constants in defined() and define() calls (#284)
1 parent b9e92e3 commit 40b8942

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

specs/const/native-const.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@
3232
3333
$x = DIRECTORY_SEPARATOR;
3434
35+
if (!defined('PATH_SEPARATOR')) {
36+
define('PATH_SEPARATOR', "\n");
37+
}
38+
3539
----
3640
<?php
3741
3842
namespace Humbug\Acme;
3943
4044
$x = \DIRECTORY_SEPARATOR;
45+
if (!\defined('PATH_SEPARATOR')) {
46+
\define('PATH_SEPARATOR', "\n");
47+
}
4148

4249
PHP
4350
,
@@ -51,13 +58,20 @@
5158
5259
$x = DIRECTORY_SEPARATOR;
5360
61+
if (!defined('PATH_SEPARATOR')) {
62+
define('PATH_SEPARATOR', "\n");
63+
}
64+
5465
----
5566
<?php
5667
5768
namespace Humbug\Acme;
5869
5970
use const Humbug\Acme\DIRECTORY_SEPARATOR;
6071
$x = \Humbug\Acme\DIRECTORY_SEPARATOR;
72+
if (!\defined('PATH_SEPARATOR')) {
73+
\define('PATH_SEPARATOR', "\n");
74+
}
6175

6276
PHP
6377
,

src/PhpParser/NodeVisitor/StringScalarPrefixer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ private function prefixStringArg(String_ $string, Arg $parentNode): String_
180180
;
181181
}
182182

183-
return ($this->whitelist->isSymbolWhitelisted($string->value, true)
183+
return
184+
(
185+
$this->whitelist->isSymbolWhitelisted($string->value, true)
184186
|| $this->whitelist->isGlobalWhitelistedConstant($string->value)
187+
|| $this->reflector->isConstantInternal($string->value)
185188
)
186189
? $string
187190
: $this->createPrefixedString($string)

0 commit comments

Comments
 (0)