How to get the namespace where the function is called?

Asked

Viewed 40 times

2

Is there any way to do that?

<?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 using call_user_func, and use this function in a namespace Foo, to call a function of the namespace Foo, how can I know that this function is passed on the namespace Foo?

  • I translated, is this wrong! I found the question interesting

  • @Wallacemaxters is not wrong, feel free to translate

1 answer

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.