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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?