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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化