Page MenuHomePhabricator

D10537.id26938.diff
No OneTemporary

D10537.id26938.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
@@ -50,7 +50,8 @@
const LINT_ARRAY_SEPARATOR = 48;
const LINT_CONSTRUCTOR_PARENTHESES = 49;
const LINT_DUPLICATE_SWITCH_CASE = 50;
- const LINT_BLACKLISTED_FUNCTION = 50;
+ const LINT_BLACKLISTED_FUNCTION = 51;
+ const LINT_CALL_TIME_PASS_BY_REF = 52;
private $blacklistedFunctions = array();
private $naminghook;
@@ -114,6 +115,7 @@
self::LINT_CONSTRUCTOR_PARENTHESES => 'Constructor Parentheses',
self::LINT_DUPLICATE_SWITCH_CASE => 'Duplicate Case Statements',
self::LINT_BLACKLISTED_FUNCTION => 'Use of Blacklisted Function',
+ self::LINT_CALL_TIME_PASS_BY_REF => 'Call-Time Pass-By-Reference',
);
}
@@ -211,7 +213,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '13';
+ return '14';
}
protected function resolveFuture($path, Future $future) {
@@ -285,6 +287,7 @@
'lintConstructorParentheses' => self::LINT_CONSTRUCTOR_PARENTHESES,
'lintSwitchStatements' => self::LINT_DUPLICATE_SWITCH_CASE,
'lintBlacklistedFunction' => self::LINT_BLACKLISTED_FUNCTION,
+ 'lintCallTimePassByReference' => self::LINT_CALL_TIME_PASS_BY_REF,
);
foreach ($method_codes as $method => $codes) {
@@ -2998,6 +3001,21 @@
}
}
+ protected function lintCallTimePassByReference(XHPASTNode $root) {
+ $nodes = $root->selectDescendantsOfType('n_CALL_PARAMETER_LIST');
+
+ foreach ($nodes as $node) {
+ $parameters = $node->selectDescendantsOfType('n_VARIABLE_REFERENCE');
+
+ foreach ($parameters as $parameter) {
+ $this->raiseLintAtNode(
+ $parameter,
+ self::LINT_CALL_TIME_PASS_BY_REF,
+ pht('Call-time pass-by-reference calls are prohibited.'));
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
@@ -0,0 +1,30 @@
+<?php
+class MyClass extends YourClass implements SomeInt {
+ function myfunc($var) {
+ echo $var;
+ }
+}
+
+$myvar = true;
+myfunc(&$myvar);
+myfunc($myvar);
+
+$this->myfunc(&$myvar);
+$this->myfunc($myvar);
+
+MyClass::myfunc(&$myvar);
+MyClass::myfunc($myvar);
+
+while (testfunc($var1, &$var2, $var3, &$var4) === false) {}
+
+sprintf('0%o', 0777 & $p);
+
+$foo(&$myvar);
+~~~~~~~~~~
+error:2:7 XHP19
+error:9:8
+error:12:15
+error:15:17
+error:18:24
+error:18:39
+error:22:6

File Metadata

Mime Type
text/plain
Expires
Thu, Aug 21, 12:10 AM (1 d, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
9667102
Default Alt Text
D10537.id26938.diff (2 KB)

Event Timeline