0

Quite some time ago I wrote a RSS parser. It worked fine until now, when I turned my error and notice reporting on. Currently I keep getting quite a lot of notices that tell me that something is wrong in the function. I tried solving this problem on my own, but I had no success. Could You please help me with this error?

The error:

Notice: Undefined index: RSS in C:\xampp\htdocs\Dropbox\RECtus\System\sysFiles\libarys\myRSSParser.lib(103) : eval()'d code on line 1

Notice: Undefined index: LINK in C:\xampp\htdocs\Dropbox\RECtus\System\sysFiles\libarys\myRSSParser.lib(103) : eval()'d code on line 1

The script:

function parseData($parser, $data) {
        if(!trim($data)) return;
        $RSS = '';
        $evalcode = "\$this->output";

        foreach($this->tags as $tag) {
            if(is_array($tag)) {
                list($tagname, $indexes) = each($tag);

                $evalcode .= "[\"$tagname\"]";
                if(!isset(${$tagname})) ${$tagname} = '';
                if(${$tagname}) $evalcode .= "[" . (${$tagname} - 1) . "]";
                if($indexes) extract($indexes); 
            } else {
                if(preg_match("/^([A-Z]+):([A-Z]+)$/", $tag, $matches)) {
                    $evalcode .= "[\"$matches[1]\"][\"$matches[2]\"]";
                } else {
                    $evalcode .= "[\"$tag\"]";
                }
            }
        }
        eval("$evalcode = $evalcode . '" . addslashes($data) . "';");
}

Line 103 is the eval() line.

10
  • Please provide a dump of $evalcode just before the eval(). Also, one of the two $evalcode strings in the eval() call should probably be escaped, e.g. eval("\$evalcode = $evalcode . '" ... Commented Apr 1, 2011 at 10:52
  • Eval is evil! (i.e. don't use eval) Commented Apr 1, 2011 at 10:52
  • 4
    I would say the real problem is that you're using eval() in the first place. There are several XML parsers and a few RSS-specific XML parsers available for PHP ... The best way to really solve your problem is not using eval(), it's notoriously hard to debug and prone to errors. Commented Apr 1, 2011 at 10:53
  • have you tried echo on eval argument to see what eval() tries to evaluate? Commented Apr 1, 2011 at 10:53
  • 2
    [putting flame retardant suit on] code is crap. Abandon you "solution" entirely, and write a new one, you are looking for error in fatal error. Commented Apr 1, 2011 at 10:55

1 Answer 1

2

Why are you using eval() ?

It seems you're just trying to concatenate portions of string, no ?

If so, why not just... concatenate portions of strings ?


Basically, you should be able to do something like this :
$this->output = array();
$this->output['...'] = 'some string';
$this->output['...'] = array();
$this->output['...']['...'] = 'some other string';
Sign up to request clarification or add additional context in comments.

2 Comments

This is not what his code is doing. It’s rather something like $this->output[…] = $this->output[…].$data.
@Gumbo : ergh, you're right! Thanks for your comment, I've edited my answer a bit :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.