一个类中的多个API调用 [英] Multiple API Calls in a Class
问题描述
我正在尝试发出多个API请求,并且必须在类似这样的类中的不同函数中发出请求:
I am trying to make multiple API requests and I have to make the request in different functions that are within a class like so:
class exampleClass
{
function callFunction1 () {
// stuff that makes a call
return $json;
}
function printStuffOut() {
$jsonStuff = $this->callFunction1();
$$jsonStuff->{'result'}[0]->{'fieldName'};
}
function printStuffOut2() {
$jsonStuff = $this->callFunction1();
$jsonStuff->{'result'}[0]->{'fieldName'};
}
}
我要进行两个单独的API调用吗?
Am I making two separate API calls?
如果我愿意,是否可以将API调用信息存储在数组中,然后在我班上的所有其他函数中使用该数组?
If I am, is there a way to store that API call information say in an array then use that array in all the other functions in my class?
推荐答案
第一个问题的答案:是的,每次调用该方法时,它都会再次执行其所有定义.
Answer to first question: Yes you are, each time the method is called it executes all its definition again.
回答第二个问题:是的,有所谓的成员属性.您可以在以下PHP手册中阅读有关它们的信息: PHP手册:属性
Answer to second question: Yes there is, so called member properties. You can read up about them in the PHP manual here: PHP Manual: Properties
这篇关于一个类中的多个API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!