| View previous topic :: View next topic |
| Author |
Message |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Tue Aug 18, 2015 4:41 pm Post subject: Anyone know any php? WTB Halp. |
|
|
| Is there anyone with moderate proficiency in php that could aid me in figuring out why I a program I am writing won't recognize that a function exists, even though it's written like many other functions that work properly. I can provide additional details if there is someone who knows something.
|
|
| Back to top |
|
 |
Aniblaze Grandmaster Cheater Supreme
Reputation: 138
Joined: 23 Apr 2006 Posts: 1757 Location: The Netherlands
|
Posted: Tue Aug 18, 2015 5:10 pm Post subject: |
|
|
| I am extremely proficient in PHP.
|
|
| Back to top |
|
 |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Tue Aug 18, 2015 5:23 pm Post subject: |
|
|
Right, so I forked some guy's php wrapper of Riot's api, and when I use the functions, they all work well; however, when I tried to implement my own, it failed to find that the function existed.
| Code: |
<?php
include('php-riot-api.php');
$test = new riotapi('na');
$r = $test->getMatch(1852548676);
//pulls the item id out of the array.
$item0 = $r['participants'][0]['stats']['item0'];
//retrieves item info
$item0info = getItem($item0);
print_r($item0info)
?>
|
Edit: I wasn't calling the function with $test->getItem(), because I am a novice. Fixed now, thanks though.
|
|
| Back to top |
|
 |
Aniblaze Grandmaster Cheater Supreme
Reputation: 138
Joined: 23 Apr 2006 Posts: 1757 Location: The Netherlands
|
Posted: Wed Aug 19, 2015 8:53 am Post subject: |
|
|
| HackOtaku wrote: | Right, so I forked some guy's php wrapper of Riot's api, and when I use the functions, they all work well; however, when I tried to implement my own, it failed to find that the function existed.
| Code: |
<?php
include('php-riot-api.php');
$test = new riotapi('na');
$r = $test->getMatch(1852548676);
//pulls the item id out of the array.
$item0 = $r['participants'][0]['stats']['item0'];
//retrieves item info
$item0info = getItem($item0);
print_r($item0info)
?>
|
Edit: I wasn't calling the function with $test->getItem(), because I am a novice. Fixed now, thanks though. |
Ah. Object oriented stuff. Godspeed man.
|
|
| Back to top |
|
 |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Wed Aug 19, 2015 3:19 pm Post subject: |
|
|
| Thanks, I don't have a firm grasp on php, I just understand data structures and C-syntax programming, but I'm hoping to figure it out.
|
|
| Back to top |
|
 |
potaters Grandmaster Cheater
Reputation: 72
Joined: 13 Apr 2009 Posts: 969
|
Posted: Wed Aug 19, 2015 10:18 pm Post subject: |
|
|
I do OOP PHP,
| Code: | //retrieves item info
$item0info = getItem($item0); |
if u added a method called 'getItem' to the 'riotapi' class it would be called like:
| Code: | | $test->getItem($item0); |
Last edited by potaters on Thu Aug 20, 2015 8:00 pm; edited 1 time in total |
|
| Back to top |
|
 |
Nirojan How do I cheat?
Reputation: 108
Joined: 16 Sep 2008 Posts: 0 Location: seshville
|
Posted: Thu Aug 20, 2015 12:36 am Post subject: |
|
|
pass me the drink i po it up
im about to double up my styrofoam cup
im to faded i cant even dap you up
_________________
| Quote: | | yo i b 22 tryna make it in dis rap game but da steetz dont got luv for no wun na mean so im out hea tryna holla at da fams on dis innernet shit u no way i sayin |
|
|
| Back to top |
|
 |
CEForumMember Expert Cheater
Reputation: 4
Joined: 06 Jul 2015 Posts: 110
|
Posted: Thu Aug 20, 2015 12:58 am Post subject: |
|
|
For a second I thought I was in general programming section.
_________________
|
|
| Back to top |
|
 |
Aniblaze Grandmaster Cheater Supreme
Reputation: 138
Joined: 23 Apr 2006 Posts: 1757 Location: The Netherlands
|
Posted: Thu Aug 20, 2015 7:37 am Post subject: |
|
|
| potaters wrote: | I do OOP PHP,
| Code: | //retrieves item info
$item0info = getItem($item0); |
if u added a function called 'getItem' to the 'riotapi' class it would be called like:
| Code: | | $test->getItem($item0); |
|
He already figured that out a day before you posted this.
|
|
| Back to top |
|
 |
potaters Grandmaster Cheater
Reputation: 72
Joined: 13 Apr 2009 Posts: 969
|
Posted: Thu Aug 20, 2015 2:12 pm Post subject: |
|
|
| Nirojan wrote: | pass me the drink i po it up
im about to double up my styrofoam cup
im to faded i cant even dap you up |
RIP SK!!!!!!!!!!!!!!!
|
|
| Back to top |
|
 |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Thu Aug 20, 2015 2:45 pm Post subject: |
|
|
Yee, I did figure that out, but I still need help if you guys know why this might be an issue.
| Code: | $players = array();
//for each of the 10 players
for ($i = 0; $i<10;$i++){
$item = array();
//for each of the 7 items
for($j = 0; $j < 7; $j++){
//creates a string to retrieve data
$req = "item" . $j ;
//stores the appropriate item in the array
$itemid = $r['participants'][$j]['stats'][$req];
$item = $apiCache->getItem($itemid);
echo "\n\n\n\n";
print_r($item);
echo "\n\n\n\n";
$item[$j] = $item["name"];
}
$players[$i] = array($item[0], $item[1], $item[2], $item[3], $item[4], $item[5], $item[6]);
}
|
The basics is that there are 10 players, each with 7 items, and I want to collect data on what each of those items are. I used this to try and build a 2-d array, but it doesn't work. The return value of $apiCache->getItem($itemid);
is an object containing ["id"]["name"]["description"] and ["plaintext"], but when I try to story the item name in $item[$j], it gives me "illegal string offset. I think it is possible that the entirety of the object is being stored as a string, but I'm not sure what the solution is.
|
|
| Back to top |
|
 |
Aniblaze Grandmaster Cheater Supreme
Reputation: 138
Joined: 23 Apr 2006 Posts: 1757 Location: The Netherlands
|
Posted: Thu Aug 20, 2015 4:43 pm Post subject: |
|
|
| HackOtaku wrote: | Yee, I did figure that out, but I still need help if you guys know why this might be an issue.
| Code: | $players = array();
//for each of the 10 players
for ($i = 0; $i<10;$i++){
$item = array();
//for each of the 7 items
for($j = 0; $j < 7; $j++){
//creates a string to retrieve data
$req = "item" . $j ;
//stores the appropriate item in the array
$itemid = $r['participants'][$j]['stats'][$req];
$item = $apiCache->getItem($itemid);
echo "\n\n\n\n";
print_r($item);
echo "\n\n\n\n";
$item[$j] = $item["name"];
}
$players[$i] = array($item[0], $item[1], $item[2], $item[3], $item[4], $item[5], $item[6]);
}
|
The basics is that there are 10 players, each with 7 items, and I want to collect data on what each of those items are. I used this to try and build a 2-d array, but it doesn't work. The return value of $apiCache->getItem($itemid);
is an object containing ["id"]["name"]["description"] and ["plaintext"], but when I try to story the item name in $item[$j], it gives me "illegal string offset. I think it is possible that the entirety of the object is being stored as a string, but I'm not sure what the solution is. |
Can you post the method "getItem($itemid)"?
|
|
| Back to top |
|
 |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Thu Aug 20, 2015 4:57 pm Post subject: |
|
|
| Code: | public function getItem($id){
$call = 'item/' . $id;
//add API URL to the call
$call = self::API_URL_STATIC_1_2 . $call;
return $this->request($call);
} |
request:
| Code: | private function request($call, $otherQueries=false, $static = false) {
//format the full URL
$url = $this->format_url($call, $otherQueries);
//caching
if($this->cache !== null && $this->cache->has($url)){
$result = $this->cache->get($url);
} else {
// Check rate-limiting queues if this is not a static call.
if (!$static) {
$this->updateLimitQueue($this->longLimitQueue, self::LONG_LIMIT_INTERVAL, self::RATE_LIMIT_LONG);
$this->updateLimitQueue($this->shortLimitQueue, self::SHORT_LIMIT_INTERVAL, self::RATE_LIMIT_SHORT);
}
//call the API and return the result
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($this->responseCode == 200) {
if($this->cache !== null){
$this->cache->put($url, $result, self::CACHE_LIFETIME_MINUTES * 60);
}
if (self::DECODE_ENABLED) {
$result = json_decode($result, true);
}
} else {
throw new Exception(self::$errorCodes[$this->responseCode]);
}
}
return $result;
} |
|
|
| Back to top |
|
 |
Aniblaze Grandmaster Cheater Supreme
Reputation: 138
Joined: 23 Apr 2006 Posts: 1757 Location: The Netherlands
|
Posted: Thu Aug 20, 2015 5:29 pm Post subject: |
|
|
| HackOtaku wrote: | | Code: | public function getItem($id){
$call = 'item/' . $id;
//add API URL to the call
$call = self::API_URL_STATIC_1_2 . $call;
return $this->request($call);
} |
request:
| Code: | private function request($call, $otherQueries=false, $static = false) {
//format the full URL
$url = $this->format_url($call, $otherQueries);
//caching
if($this->cache !== null && $this->cache->has($url)){
$result = $this->cache->get($url);
} else {
// Check rate-limiting queues if this is not a static call.
if (!$static) {
$this->updateLimitQueue($this->longLimitQueue, self::LONG_LIMIT_INTERVAL, self::RATE_LIMIT_LONG);
$this->updateLimitQueue($this->shortLimitQueue, self::SHORT_LIMIT_INTERVAL, self::RATE_LIMIT_SHORT);
}
//call the API and return the result
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($this->responseCode == 200) {
if($this->cache !== null){
$this->cache->put($url, $result, self::CACHE_LIFETIME_MINUTES * 60);
}
if (self::DECODE_ENABLED) {
$result = json_decode($result, true);
}
} else {
throw new Exception(self::$errorCodes[$this->responseCode]);
}
}
return $result;
} |
|
Wasn't actually needed looking at it now. So for reference, $item = $apiCache->getItem($itemid); contains the array, so after this line I can assume that $item looks as followed:
| Code: |
$item["id"] = '???';
$item["name"] = '???';
$item["description"] = '???';
$item["plaintext"] = '???';
|
So basically an associative array. I am pretty sure that $item[0] through $item[6] wouldn't exist then.
|
|
| Back to top |
|
 |
HackOtaku I posted the 500000th topic
Reputation: 81
Joined: 31 May 2007 Posts: 228
|
Posted: Thu Aug 20, 2015 5:56 pm Post subject: |
|
|
oh, lol, I named $item as an array, then as the return object.
I changed it to $itemAr, but the issue is that
$itemAr[$j] = $item["name"];
when I attempt that, it tells me "name" is an illegal string offset, even though I can see the data in front of me.
| Description: |
|
| Filesize: |
67.82 KB |
| Viewed: |
5873 Time(s) |

|
|
|
| Back to top |
|
 |
|