EmpireJones EmpireJones - 1 year ago 75
PHP Question

Can PHP namespaces contain variables?

Can PHP namespaces contain variables? If so, how can this be accomplished?

Answer Source

No. You can set a variable after declaring a namespace, but variables will always exist in the global scope. They are never bound to namespaces. You can deduce that from the absence of any name resolution descriptions in

There would also be no allowed syntax to locate variables in a namespace.

print \namespace\$var;      // syntax error

print "${namespace\\var}";  // "unexpected T_NS_SEPARATOR"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download