duanaoou4105 2013-12-13 15:12
浏览 50
已采纳

在另一个公共函数中使用一个公共函数

The title may not make sense, not sure how to word it. Anyways, i'm practicing curl and OOP at the same time here with the riot games API. the API is kind of set up dumb where some info you want to request requires input that you wouldn't know off hand, so it requires another separate call to get the required info first.

class league
{
    const URL = 'http://prod.api.pvp.net/api/lol/na/v1.1/';
    const URL_2 = 'http://prod.api.pvp.net/api/lol/na/v2.1/';
    const KEY = 'key';

    public function summonerByName($summoner_name)
    {
        $request = 'summoner/by-name/' . $summoner_name . '?api_key =' . self::KEY;
        return $this->fetch($request);
    }

    public function recentGamesByName($summoner_name)
    {
        //need to make two calls for this since you cant get recent games by name in the api

        $id = summonerByName($summoner_name);

        //now get recent games
        $request = 'game/by-summoner/' . $id->id . '/recent';
        return $this->fetch($request);
    }   


    private function fetch($request)
    {
        $url = self::URL . $request . '?api_key=' . self::KEY;
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl);
        curl_close($curl);
        return json_decode($data);
    }
}

this is returning Fatal error: Call to undefined function summonerbyname()

if i use all this extra code below in the public function recentGamesByName() instead of $id = summonerByName() it works fine, but it seems unnecessary, and i want to replace that with just the function.

$grg = self::URL . 'summoner/by-name/' . $summoner_name . '?api_key=' . self::KEY;
$placeholder = curl_init($grg);
curl_setopt($placeholder, CURLOPT_RETURNTRANSFER, 1);
$ph_result = curl_exec($placeholder);
curl_close($placeholder);
$ph_result = json_decode($ph_result);
  • 写回答

2条回答 默认 最新

  • duandang6111 2013-12-13 15:13
    关注

    $id = $this->summonerByName($summoner_name);

    You may want to read up on OOP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作