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
F13092258: D14516.diff
Thu, Apr 25, 3:33 AM
Unknown Object (File)
Sat, Apr 13, 12:29 PM
Unknown Object (File)
Tue, Apr 2, 7:51 AM
Unknown Object (File)
Mar 20 2024, 9:45 PM
Unknown Object (File)
Mar 7 2024, 4:56 PM
Unknown Object (File)
Mar 6 2024, 5:23 AM
Unknown Object (File)
Mar 6 2024, 5:22 AM
Unknown Object (File)
Mar 6 2024, 4:46 AM
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.