开发者

Member Function and a non-object

开发者 https://www.devze.com 2023-01-05 07:16 出处:网络
I have created a simple function for fetching xml: function meteor(){ $request_url = \"http://site.com/xml.xml\";

I have created a simple function for fetching xml:

function meteor(){
    $request_url = "http://site.com/xml.xml";
    $xml = simplexml_load_file($request_url开发者_StackOverflow社区) 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


$xmls = meteor();
$xmls->Kemo->Area;


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:

$xmls = meteor();


meteor is a function not a class. i don't think you can create a

new meteor();


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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消