]> khamidou — GitHub mirrors - arcanist.git/commit
Write a linter rule for unexpected `return` values
authorJoshua Spence <josh@freelancer.com>
Thu, 19 Nov 2015 08:34:32 +0000 (19:34 +1100)
committerJoshua Spence <josh@freelancer.com>
Thu, 19 Nov 2015 08:34:32 +0000 (19:34 +1100)
commit3ac313ad1e65c3d08a0909aa2690a8458153fd06
treeb22472c02b3f6b5cdcc11072c46de9fc584b18ee
parent149e7895fbd5e35f804e6f0b77d7788a988bc2f9
Write a linter rule for unexpected `return` values

Summary:
Although it is technically possible to return a value from a PHP constructor, it is rather odd and should be avoided. See some discussion on [[http://stackoverflow.com/q/11904255 | StackOverflow]]. Consider the following example:

```lang=php
class SomeClass {
  public function __construct() {
    return 'quack';
  }
}
```

This doesn't work:

```lang=php, counterexample
echo new SomeClas();
```

This, strangely, does work:

```lang=php
echo id(new SomeClass())->__construct();
```

Test Plan: Added unit tests.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14516
src/__phutil_library_map__.php
src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase.php [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/construct.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/destruct.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/empty-return.lint-test [new file with mode: 0644]