Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Sep 19 Previous

Item 547229

PHP Namespaces provide a way to group related items. Which items can be encapsulated in namespaces:

A: classes
B: interfaces
C: functions
D: constants
E: variables

Choose all that apply.


Only variables (answer E) cannot be encapsulated by a namespace. They can be declared within a namespace but they will become part of the global scope and not of the namespace. So if you need to access a variable that was decared in a namespace look in global scope.

A note on constants. Those declared using const can be part of namespaces, those declared using define() cannot. However the latter can be made to look like that they are part of a namespace by using tricks as:

define(__NAMESPACE__."CONST", 1);


Now the namespace is part of the constant name and you can reference it using namespace syntax. But it's faked so you can't use aliases for instance.