How to get the namespace where the function is called?

2

Is there any way to do this?

<?php

namespace Bar {
    class test {
        public function test($action) {
            call_user_func($action); // must call \Foo\Action
        }
    }
}

namespace Foo {
    $test = new \Bar\Test;

    function action () {
        echo 'it works!';
    }

    $test->test('action');
}

For a more detailed description: If I have a function that calls user-defined functions with the use of call_user_func , and use that function in a Foo namespace, to call a namespace Foo function like me can I know that this function is passed on namespace Foo ?

    
asked by anonymous 25.08.2015 / 15:16

1 answer

0

You can get the value of $ action, "explode" it with $ array = explode ("\", $ action) and remove the last value from the array generated with array_pop () and then merge the rest with implode (" \ ", $ array)

    
29.08.2015 / 02:58