Page MenuHomePhabricator

Consider magic scalars to be constant strings
ClosedPublic

Authored by joshuaspence on Apr 4 2015, 3:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 10, 12:51 AM
Unknown Object (File)
Sun, Dec 8, 7:20 AM
Unknown Object (File)
Sun, Dec 8, 12:01 AM
Unknown Object (File)
Sat, Dec 7, 4:26 PM
Unknown Object (File)
Sat, Dec 7, 9:38 AM
Unknown Object (File)
Thu, Dec 5, 10:05 PM
Unknown Object (File)
Sun, Dec 1, 7:37 AM
Unknown Object (File)
Wed, Nov 27, 11:06 AM
Subscribers

Details

Summary

Consider magic scalars such as __DIR__ to be constant strings. I am using this to determine if a path that is imported with require_once is autoloadable, see D12271 for some additional context.

Test Plan

Tested externally with a custom linter.

Diff Detail

Repository
rPHU libphutil
Branch
master
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 5170
Build 5188: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

joshuaspence retitled this revision from to Consider magic scalars to be constant strings.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence edited edge metadata.

Ah yeah, I thought this seemed familiar. What would need to happen for this to move forward?

epriestley edited edge metadata.

I'm fine with introducing a similar method that allows n_MAGIC_SCALAR, but I think the current definition of a "constant string" is reasonable, and it's certainly the definition desired by the callsites.

If user-defined constants are also included, maybe the new method is isRuntimeConstantString(). If MAGIC is in but constants are out, maybe it's isConstantStringWithMagic() or something.

You could probably make this method private, add $include_magic and $include_constants flags or whatever, and then implement all the new methods in terms of calling it with appropriate flags? I think the number of reasonable modes is low enough not to expose the actual flags as part of the public API, maybe.

This revision now requires changes to proceed.Apr 6 2015, 1:10 PM
joshuaspence edited edge metadata.

Add a separate isConstantStringWithMagicConstants method

epriestley edited edge metadata.

Consider two public APIs which take zero parameters plus one private API which requires parameters.

src/parser/xhpast/api/XHPASTNode.php
119

This should pass $additional_types?

This revision is now accepted and ready to land.Apr 6 2015, 10:03 PM
joshuaspence edited edge metadata.

Pass $additional_types to recursive method call

Two public APIs + one private API

This revision was automatically updated to reflect the committed changes.