Page MenuHomePhabricator

Classify `n_MAGIC_SCALAR` as a constant string
AbandonedPublic

Authored by joshuaspence on Sep 5 2014, 2:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 17, 10:35 PM
Unknown Object (File)
Thu, Dec 12, 7:04 AM
Unknown Object (File)
Fri, Dec 6, 5:17 PM
Unknown Object (File)
Fri, Dec 6, 4:57 AM
Unknown Object (File)
Thu, Dec 5, 1:18 AM
Unknown Object (File)
Thu, Dec 5, 12:56 AM
Unknown Object (File)
Thu, Dec 5, 12:36 AM
Unknown Object (File)
Wed, Nov 27, 6:36 PM
Subscribers

Details

Reviewers
epriestley
Group Reviewers
Blessed Reviewers
Summary

Magic scalars (__DIR__, __FILE__, etc) return false for isConstantString whereas they should probably return true.

Test Plan

Eyeball it

Diff Detail

Repository
rPHU libphutil
Branch
magicscalar
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 2443
Build 2447: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

joshuaspence retitled this revision from to Classify `n_MAGIC_SCALAR` as a constant string.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.

Hmm, what's the context/use case?

I think we mostly use this for pht(...) and qsprintf(...) right now, and pht(__FILE__) is not correct, just like define('SOMECONST', 'str'); ... pht(SOMECONST); would not be correct.

That is, we actually use this method as isConstantStringWhichCanBeEvaluatedStaticallyRightNow(), which is not true of __DIR__, __FILE__, __CLASS__, or real constants.

I am writing a custom linter and want to enforce that require_once paths are constants. We have a lot of legacy code which does require_once "$BASE_DIR/foo/bar.php" where $BASE_DIR is a global variable.