Reputation: 16656
If I have the following file:
<?php
namespace SampleProject;
hello_world();
and this in a separate file:
<?php
function hello_world() {
}
Is there anyway for the hello_world()
function to get the namespace of the file that called it (So SampleProject
)
Upvotes: 3
Views: 166
Reputation: 3819
Depends on what you want to do with that namespace information, but you could add a parameter to the function and then call it like this:
hello_world(__NAMESPACE__);
read more about the __NAMESPACE__
constant in the php documentation.
Adding __NAMESPACE__
inside your function will simply give an empty string since your function is not inside of a namespace.
Upvotes: 2