I have created a simple function for fetching xml:
我为获取xml创建了一个简单的函数:
function meteor(){
$request_url = "http://site.com/xml.xml";
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml;
}
But I cant call to this function:
但我不能调用这个函数:
$xmls = new meteor();
echo $xmls->Kemo->Area;
I have not any output because meteor in not a class. In this situation, how can fetch data from function? Thanks in advance
因为流星不在一个级别,所以我没有任何输出。在这种情况下,如何从函数中获取数据?谢谢提前
4 个解决方案
#1
5
$xmls = meteor();
$xmls->Kemo->Area;
#2
2
You can use new
only with classes, to create a new object from that class. meteor
is a function, not a class. What you want is to call the function instead, simply like this:
只能对类使用new,以从该类创建新对象。流星是一个函数,不是一个类。你想要的是调用函数,就像这样:
$xmls = meteor();
#3
1
meteor is a function not a class. i don't think you can create a
流星是一个函数而不是一个类。我认为你不能创造一个
new meteor();
#4
1
The basic code is wrong. Always remember that you cannot use the "new" keyword for instantiating functions. This "new" keyword will only work for instantiating classes into objects.
基本代码是错误的。记住,不能使用“new”关键字来实例化函数。这个“新”关键字只会用于将类实例化为对象。
Try calling the function directly into your code, for fetching the appropriate value. But before that I think you will need to modify your "meteor()" function according to what you want to achieve.
尝试将函数直接调用到代码中,以获取适当的值。但在此之前,我认为您需要根据您想要实现的目标修改您的“流星()”功能。
Hope it helps.
希望它可以帮助。
#1
5
$xmls = meteor();
$xmls->Kemo->Area;
#2
2
You can use new
only with classes, to create a new object from that class. meteor
is a function, not a class. What you want is to call the function instead, simply like this:
只能对类使用new,以从该类创建新对象。流星是一个函数,不是一个类。你想要的是调用函数,就像这样:
$xmls = meteor();
#3
1
meteor is a function not a class. i don't think you can create a
流星是一个函数而不是一个类。我认为你不能创造一个
new meteor();
#4
1
The basic code is wrong. Always remember that you cannot use the "new" keyword for instantiating functions. This "new" keyword will only work for instantiating classes into objects.
基本代码是错误的。记住,不能使用“new”关键字来实例化函数。这个“新”关键字只会用于将类实例化为对象。
Try calling the function directly into your code, for fetching the appropriate value. But before that I think you will need to modify your "meteor()" function according to what you want to achieve.
尝试将函数直接调用到代码中,以获取适当的值。但在此之前,我认为您需要根据您想要实现的目标修改您的“流星()”功能。
Hope it helps.
希望它可以帮助。