PHP question: It looks like it's possible to "use", and therefore alias, a namespaced constant. Is there any way to do the same thing with a namespaced class constant?

It's not exactly a "use", but it would seem to accomplish what you're looking for.


@kboyd Ignore the eval() part of that, btw. It's just an artifact of trying to do it all in one file.

@pollita Hmm. I guess that's about the same as what I saw (using a temp variable to store the constant's value). Was mostly hoping there was a convenient way to avoid the temp variable.

@pollita Sorry, I didn't provide full context (since it was just some code I was glancing at). I wanted to replace a temporary variable inside a method that was storing a deeply-namespaced class constant's value, with a use statement & alias. The temporary variable only exists because it's more readable than the full reference to the class constant.

Sign in to participate in the conversation
PHP Community on Mastodon

Open source. Open community. We are dedicated to building and enriching the PHP community. Join us!

Welcome to the PHP Community on Mastodon! We're a friendly little Mastodon instance providing a place for PHP developers to discuss topics related to PHP, as well as topics unrelated to PHP. First and foremost, we're about building community, and that doesn't always involve technical discussion, so feel free to go off-topic and have fun.

Before you get started, make sure you check out our code of conduct.

Thank you to Jakob Westhoff for allowing the use of the photograph "elePHPants walking through the light."