views:

50

answers:

2
foreach ($data['tests'] as $testname => $tests) {
echo "<h1>Extraction $testname Tests</h1>\n";
$function = $testfunctions[$testname];

echo "<ul>";
foreach ($tests as $test) {
    echo "<li>" . $test['description'] . ' ... ';
    $extracted = $extractor->$function($test['text']);
    if ($test['expected'] == $extracted) {
        echo " <span style='color: green'>passed.</span></li>";
    } else {
        echo " <span style='color: red'>failed.</span>";
        echo "<pre>Original: " . htmlspecialchars($test['text']) . "\nExpected: " . print_r($test['expected'], true) . "\nActual  : " . print_r($extracted, true) . "</pre>";
    }
    echo "</li>";
}
echo "</ul>";}

I keep getting the error:

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test\runtests.php on line 49

p.s. the beginning of the code is line 49, so the probelm starts with the foreach statment.

+1  A: 

One of the elements in $data["tests"] is probably not an array.

Add this before the foreach:

if (is_array($tests))
 foreach ($tests as $test) {...
Pekka
i still get the error!!!
getaway
+3  A: 

Whenever i see that, it tends to mean that the thing i'm trying to iterate through isn't an array.

Check $data['tests'] (and each inner $tests) to make sure it's not null/unset/empty, and that it's something iterable like an array. Also keep in mind that older versions of PHP (before 5.0?) don't do iterable objects very well.

cHao
i fixed the error, the array wasnt poplauted with data, its was just a bit of syntax on line 40!! :))) thanks
getaway