TheNone
TheNone

Reputation: 5802

Member Function and a non-object

I have created a simple function for fetching 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

Upvotes: 1

Views: 136

Answers (4)

Knowledge Craving
Knowledge Craving

Reputation: 7993

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.

Upvotes: 1

Thomas
Thomas

Reputation: 181785

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();

Upvotes: 2

fabrik
fabrik

Reputation: 14365

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

new meteor();

Upvotes: 1

Fidi
Fidi

Reputation: 5824

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

Upvotes: 5

Related Questions