]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Lint against undefined magic symbols
authorJoshua Spence <josh@joshuaspence.com>
Wed, 14 Jan 2015 19:55:45 +0000 (06:55 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 14 Jan 2015 19:55:45 +0000 (06:55 +1100)
Summary: Fixes T5639. Allows the detection of undefined magic symbols, such as the use of `__DIR__` in a codebase that targets <  PHP 5.3.0.

Test Plan: Added a test case.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T5639

Differential Revision: https://secure.phabricator.com/D11386

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/php53-features.lint-test

index 9ea605051fda46781902bdd5869b7c67875a85a7..bda26b9473c9e1cc8dc5e1aa35f3ba471fb38b48 100644 (file)
@@ -596,7 +596,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     // TODO: Technically, this will include function names. This is unlikely to
     // cause any issues (unless, of course, there existed a function that had
     // the same name as some constant).
-    $constants = $root->selectDescendantsOfType('n_SYMBOL_NAME');
+    $constants = $root->selectDescendantsOfTypes(array(
+      'n_SYMBOL_NAME',
+      'n_MAGIC_SCALAR',
+    ));
     foreach ($constants as $node) {
       $name = $node->getConcreteString();
       $version = idx($compat_info['constants'], $name, array());
index 1d3340daf8e94063d368a7e55be4fb05de6b18ee..5278d989a89f6e6230aa652e409567123f6b2a72 100644 (file)
@@ -10,6 +10,7 @@ static::m();
 1 ?: 2;
 $a = 'stdClass';
 $a::m();
+echo __DIR__;
 ~~~~~~~~~~
 error:3:1
 error:4:5
@@ -18,6 +19,7 @@ error:6:3
 error:7:3
 error:8:1
 error:10:1
+error:13:6
 ~~~~~~~~~~
 ~~~~~~~~~~
 {"config": {"xhpast.php-version": "5.2.3"}}