Page MenuHomePhabricator

Write a linter rule for unexpected `return` values
ClosedPublic

Authored by joshuaspence on Nov 18 2015, 11:30 PM.
Tags
None
Referenced Files
F14406682: D14516.diff
Mon, Dec 23, 7:10 PM
Unknown Object (File)
Sat, Dec 14, 3:26 AM
Unknown Object (File)
Fri, Dec 13, 6:23 PM
Unknown Object (File)
Fri, Dec 13, 8:07 AM
Unknown Object (File)
Fri, Dec 13, 7:48 AM
Unknown Object (File)
Fri, Dec 6, 3:38 AM
Unknown Object (File)
Tue, Dec 3, 5:10 PM
Unknown Object (File)
Wed, Nov 27, 11:13 PM
Subscribers

Details

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 StackOverflow. Consider the following example:

class SomeClass {
  public function __construct() {
    return 'quack';
  }
}

This doesn't work:

echo new SomeClas();

This, strangely, does work:

echo id(new SomeClass())->__construct();
Test Plan

Added unit tests.

Diff Detail

Repository
rARC Arcanist
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

joshuaspence retitled this revision from to Write a linter rule for unexpected `return` values.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.

ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase::testLinter

This one seems like it's probably related? :)

ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase::testLinter

This one seems like it's probably related? :)

I don't follow?

There are test failures, which you've excused as "Unrelated".

However, one of the test failures is in ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase, which is introduced in this diff, so it seems like it is related.

There are test failures, which you've excused as "Unrelated".

However, one of the test failures is in ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase, which is introduced in this diff, so it seems like it is related.

Oh lol

epriestley edited edge metadata.
This revision is now accepted and ready to land.Nov 18 2015, 11:48 PM
This revision was automatically updated to reflect the committed changes.