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)
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:
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.