tags:

views:

31

answers:

3

I have a script where i need to pull two seperate and different RSS feeds, break them up, assign variables, and execute code thats different for each file.

What im wondering, and i dont know if this can even be done, but once i use a function and give it settings, can i then re-use that function with different settings even though some of its internal variables will have different values?

say the first time i run it, it looks like this

$xml = simplexml_load_string($raw_xml);

foreach($xml->channel as $channel)

then i run

$xml = simplexml_load_string($raw_xml2);

foreach($xml->item as $item)

Will i get errors or redundant data because i re-used the XML variable?

+2  A: 

Not at all. Assigning a new value to a variable completely overwrites the first value. The code you posted should work fine.

zombat
A: 

Just assign it to a different variable. Very easy.

Chacha102
A: 

It totally depends on what simplexml_load_string does. Suppose the implementation uses globals:

function simplexml_load_string() {
    global $a;
    $a++; /* we're increasing the global value of $a each time the function is called */ 
}

It will definitely output unidentified behavior.

Other than that, local variables storage will be deleted and pushed on the stack everytime.

Luca Matteis
Just to clarify, `simplexml_load_string` does **not** use globals like this, this is just an example.
ceejayoz
wow, that's actually a built in PHP function? I didn't know.
Luca Matteis