一个类中的多个API调用

编程入门 行业动态 更新时间:2024-10-26 12:25:02
本文介绍了一个类中的多个API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试发出多个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调用

本文发布于:2023-10-29 13:00:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   类中   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!