Last active
November 26, 2019 10:49
-
-
Save fredemmott/1e65842fadb9e66e2359 to your computer and use it in GitHub Desktop.
XHP namespace rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh | |
class :foo:bar { | |
// - xhp__foo_bar | |
// + foo\xhp__bar | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh | |
namespace foo; | |
class :bar { | |
// - \xhp__bar - this is a BC break | |
// + \foo\xhp__bar | |
// | |
// BC break unlikely to be a practical issue as `class :bar extends :x:element {}` doesn't work (references foo\xhp__x_element) | |
} | |
class :herp:derp { | |
// - \xhp__herp_derp - BC break | |
// + PARSE ERROR | |
// Arguments for making it an error instead of \foo\herp\xhp__derp: | |
// - allowing two namespace syntaxes is weird. We allow it in the global namespace for backwards compatibility | |
// - it looks like this creates a class in the 'foo' namespace. It would actually make a class in the \foo\herp namespace | |
// - it's currently pretty broken: you can define the class, but you can't reference (or extend) :x:element and friends | |
// Arguments for allowing it: | |
// - creating :foo and :foo:helper is currently common (however, :foo and :foo-helper is also perfectly valid) | |
// - it's a bit weird to allow it in the global namespace, but not others | |
// - possibly more appropriate as a lint error than a parser error | |
// | |
// We aren't entirely sure what the right approach is. We decided to make it an error as this lets us revisit it later; | |
// if we allowed it, we can't ban it in the future without breaking people's code. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh | |
namespace foo; | |
$x = <x:frag />; // \foo\x\xhp__frag | |
$x = <:x:frag />; // \x\xhp__frag | |
use x as x; | |
$x = <x:frag />; // \x\xhp__frag | |
use hhvm\xhpbootstrap as bs; | |
$x = <bs:jumbotron />; // \hhvm\xhpbootstrap\xhp__jumbotron | |
$x = <:hhvm:xhpbootstrap:jumbotron />; // same |
Also
use foo\bar\{
:herp,
:derp
};
$x = <herp><derp /></herp>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also need