Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15401897
D13841.id33422.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D13841.id33422.diff
View Options
diff --git a/src/lint/linter/__tests__/xhpast/php54-features.lint-test b/src/lint/linter/__tests__/xhpast/php54-features.lint-test
--- a/src/lint/linter/__tests__/xhpast/php54-features.lint-test
+++ b/src/lint/linter/__tests__/xhpast/php54-features.lint-test
@@ -6,9 +6,26 @@
// The check above should be this, see T4334.
// $o->m()[0];
+final class SomeClass extends Phobject {
+ public function someMethod() {
+ return function () {
+ $this->someOtherMethod();
+ };
+ }
+
+ public static function someStaticMethod() {
+ return function () {
+ self::someOtherMethod();
+ };
+ }
+}
+
~~~~~~~~~~
error:3:5
error:4:9
+error:9:13
+error:12:7
+error:18:7
~~~~~~~~~~
~~~~~~~~~~
{
diff --git a/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php
@@ -371,6 +371,52 @@
break;
}
}
+
+ $closures = $this->getAnonymousClosures($root);
+ foreach ($closures as $closure) {
+ $static_accesses = $closure
+ ->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
+
+ foreach ($static_accesses as $static_access) {
+ $class = $static_access->getChildByIndex(0);
+
+ if ($class->getTypeName() != 'n_CLASS_NAME') {
+ continue;
+ }
+
+ if (strtolower($class->getConcreteString()) != 'self') {
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $class,
+ pht(
+ 'The use of `%s` in an anonymous closure is not '.
+ 'available before PHP 5.4.',
+ 'self'));
+ }
+
+ $property_accesses = $closure
+ ->selectDescendantsOfType('n_OBJECT_PROPERTY_ACCESS');
+ foreach ($property_accesses as $property_access) {
+ $variable = $property_access->getChildByIndex(0);
+
+ if ($variable->getTypeName() != 'n_VARIABLE') {
+ continue;
+ }
+
+ if ($variable->getConcreteString() != '$this') {
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $variable,
+ pht(
+ 'The use of `%s` in an anonymous closure is not '.
+ 'available before PHP 5.4.',
+ '$this'));
+ }
+ }
}
private function lintPHP54Incompatibilities(XHPASTNode $root) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 18, 7:41 PM (1 w, 10 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7710303
Default Alt Text
D13841.id33422.diff (2 KB)
Attached To
Mode
D13841: Improve PHP compatibility linter
Attached
Detach File
Event Timeline
Log In to Comment