From: Joshua Spence Date: Wed, 14 Jan 2015 19:55:45 +0000 (+1100) Subject: Lint against undefined magic symbols X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=7aa89ddf96209b53b0812b6ef4ba4ebfbdbf3379;p=arcanist.git Lint against undefined magic symbols 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 --- diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 9ea60505..bda26b94 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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()); diff --git a/src/lint/linter/__tests__/xhpast/php53-features.lint-test b/src/lint/linter/__tests__/xhpast/php53-features.lint-test index 1d3340da..5278d989 100644 --- a/src/lint/linter/__tests__/xhpast/php53-features.lint-test +++ b/src/lint/linter/__tests__/xhpast/php53-features.lint-test @@ -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"}}