Using namespace in if / else statements

前端 未结 4 619
一个人的身影
一个人的身影 2020-12-09 12:59

I am manipulating the same file to manage two external api classes.

One api class is based on namespaces, the other one is not.

What I would like to do is s

4条回答
  •  [愿得一人]
    2020-12-09 13:25

    Alright, just confirming what i said was true.. Try something like this :

    *Test_1.php*

    $API = "test_1";
    if ($API === "test"){
    
    }elseif ($API === "test_1"){
        require ("test.php");
        $API = new daryls\testt;
    }
    
    $API->test();
    

    test.php

    namespace daryls;
    class  testt {
        public function test(){
            echo "Started"; 
        }
    }
    

    Running this has worked without a hitch

提交回复
热议问题