Page MenuHomePhabricator

D12870.id31004.diff
No OneTemporary

D12870.id31004.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -67,6 +67,7 @@
const LINT_ALIAS_FUNCTION = 65;
const LINT_CAST_SPACING = 66;
const LINT_TOSTRING_EXCEPTION = 67;
+ const LINT_LAMBDA_FUNC_FUNCTION = 68;
private $blacklistedFunctions = array();
private $naminghook;
@@ -209,6 +210,8 @@
=> pht('Cast Spacing'),
self::LINT_TOSTRING_EXCEPTION
=> pht('Throwing Exception in %s Method', '__toString'),
+ self::LINT_LAMBDA_FUNC_FUNCTION
+ => pht('%s Function', '__lambda_func'),
);
}
@@ -329,7 +332,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '29';
+ return '30';
}
protected function resolveFuture($path, Future $future) {
@@ -423,6 +426,7 @@
'lintAliasFunctions' => self::LINT_ALIAS_FUNCTION,
'lintCastSpacing' => self::LINT_CAST_SPACING,
'lintThrowExceptionInToStringMethod' => self::LINT_TOSTRING_EXCEPTION,
+ 'lintLambdaFuncFunction' => self::LINT_LAMBDA_FUNC_FUNCTION,
);
foreach ($method_codes as $method => $codes) {
@@ -4156,6 +4160,38 @@
}
}
+ private function lintLambdaFuncFunction(XHPASTNode $root) {
+ $function_declarations = $root
+ ->selectDescendantsOfType('n_FUNCTION_DECLARATION');
+
+ foreach ($function_declarations as $function_declaration) {
+ $function_name = $function_declaration->getChildByIndex(2);
+
+ if ($function_name->getTypeName() == 'n_EMPTY') {
+ // Anonymous closure.
+ continue;
+ }
+
+ if ($function_name->getConcreteString() != '__lambda_func') {
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $function_declaration,
+ self::LINT_LAMBDA_FUNC_FUNCTION,
+ pht(
+ 'Declaring a function named %s causes any call to %s to fail. '.
+ 'This is because %s eval-declares the function %s, then '.
+ 'modifies the symbol table so that the function is instead '.
+ 'named %s, and returns that name.',
+ '__lambda_func',
+ 'create_function',
+ 'create_function',
+ '__lambda_func',
+ '"\0lambda_".(++$i)'));
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
diff --git a/src/lint/linter/__tests__/xhpast/lamba-func-function.lint-test b/src/lint/linter/__tests__/xhpast/lamba-func-function.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/lamba-func-function.lint-test
@@ -0,0 +1,4 @@
+<?php
+function __lambda_func() {}
+~~~~~~~~~~
+error:2:1

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 15, 9:58 AM (4 w, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6712454
Default Alt Text
D12870.id31004.diff (2 KB)

Event Timeline