xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Support `::namespace` to resolve namespace names #137

Closed thekid closed 2 years ago

thekid commented 2 years ago

Before:

namespace de\thekid\shorturl;

new RestApi(new ResourcesIn('de.thekid.shorturl.api'));

// or (with a somewhat ugly string concatenation):
new RestApi(new ResourcesIn(__NAMESPACE__.'\\api'));

// or (with the overhead of XP reflection):
new RestApi(new ResourcesIn(typeof($this)->getPackage()->getPackage('api'));

// Alternatively, the `::class` construct will work here, too. However, the 
// code does not convey the meaning very well!
// new RestApi(new ResourcesIn(api::class));

After:

namespace de\thekid\shorturl;

new RestApi(new ResourcesIn(api::namespace));
thekid commented 2 years ago

This conflicts with class constants named namespace:

$ xp -w 'class T { const namespace = "test"; } return T::namespace;'
test