I want to imitate this method of calling. How should I write it?

public function exchangeComponentAccessToken(){
        $values["config"]["app_id"] = "xxx";
        $values["config"]["secret"] = "xxx";
        $values["config"]["verify_ticket"] = "xxxx";
        $app = new Container($values); //
        
        $AccessToken = new AccessToken($app);

    }
//$this->app 
return [
            "component_appid" => $this->app["config"]["app_id"],
            "component_appsecret" => $this->app["config"]["secret"],
            //,,,
            "component_verify_ticket" => $this->app["verify_ticket"]->getTicket(),
];
Aug.30,2021

first of all, your call is $this- > app ['verify_ticket']-> getTicket () , indicating that $this- > app [' verify_ticket'] must store an instantiated object. Cannot be a closure or function.

can be implemented with a class.

class A
{
    public function getTicket()
    {
        return 'aaa';
    }
}

$c = new A();


$data['verify_ticket'] = $c;

echo $c->getTicket();

either use anonymous methods directly, but you can't call -> in this way:

$data['verify_ticket']['getTicket'] = function(){
        return 'aaa';
    };
//

$data['verify_ticket']['getTicket']();

is that what you want?

Menu