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)
Thu, Oct 10, 6:04 AM
Unknown Object (File)
Wed, Oct 2, 8:01 AM
Unknown Object (File)
Sep 12 2024, 4:08 AM
Unknown Object (File)
Sep 12 2024, 4:08 AM
Unknown Object (File)
Sep 12 2024, 4:08 AM
Unknown Object (File)
Sep 12 2024, 4:07 AM
Unknown Object (File)
Sep 11 2024, 7:38 PM
Unknown Object (File)
Sep 4 2024, 8:13 PM
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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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
127

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.