Define global function from within PHP namespace
namespaces, php
Solution
It's possible but aside from being bad design, you will have to enclose your code within brackets for each namespace and won't be able to use `namespace my_module;` Instead it will have to be `namespace my_module { ... }`.
Example:
namespace my_module {
function module_function()
{
// code
}
}
namespace {
// global namespace.
function my_module()
{
// call your namespaced code
}
}
Problem
Is it possible to define a global function from within a PHP namespace (within a file that has a namespace declaration)? If so, how? ``` <?php namespace my_module; # bunch of namespaced functions # ... # then I want to define a global function my_module() # that is an alias to my_module\mymodule() ```