PHP code example of brightnucleus / namespace-backtracer

1. Go to this page and download the library: Download brightnucleus/namespace-backtracer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brightnucleus / namespace-backtracer example snippets




namespace CalleeNamespace {

    use BrightNucleus\NamespaceBacktracer\NamespaceBacktracerTrait;

    class Callee {

        use NamespaceBacktracerTrait;

        protected function getIgnoredInterfaces() {
            return [
                'CalleeNamespace\Callee',
            ];
        }

        public function calledFunctionGetCaller() {
            echo $this->getCaller();
        }

        public function calledFunctionGetNamespace() {
            echo $this->getCallingNamespace();
        }
    }

}

namespace CallerNamespace {

    use CalleeNamespace\Callee;

    class Caller {

        public function callingFunctionGetCaller() {
            $callee = new Callee();
            $callee->calledFunctionGetCaller();
        }

        public function callingFunctionGetNamespace() {
            $callee = new Callee();
            $callee->calledFunctionGetNamespace();
        }
    }
}

$caller = new CallerNamespace\Caller();

// This will echo "CallerNamespace\Caller" from within the
// CalleeNamespace\Callee\calledFunction() method.
$caller->callingFunctionGetCaller();

// This will echo "CallerNamespace" from within the
// CalleeNamespace\Callee\calledFunction() method.
$caller->callingFunctionGetNamespace();