Disclaimer: I'm new to object-oriented PHP and I'm generally terrible at the language.
So I've got a class called "Page" in a file (class_lib.php) and I've created this variable and written a while/for loop that processes it when its set:
public $extra= "";
if (isset($this->extra)) {
echo "<table id=\"tab\">";
while (list($counter) = each($this->$extra)) {
for ($i=0;$i<3;$i++) {
echo "<tr class=\"tl\">";
echo "<td>$counter[$i]</td>";
echo "</tr>";
}
}
}
On one page, I need a table printed out. The data for this is in an array:
$page->extra = array( array('Track no.', 'Track title', 'Track length'),
array('01', 'Value1', 'No1'),
array('02', 'Value2', 'No2'),
array('03', 'Value3', 'No3'),
array('04', 'Value4', 'No4'),
array('05', 'Value5', 'No5'),
array('06', 'Value6', 'No6'),
array('07', 'Value7', 'No7'),
array('08', 'Value8', 'No8'),
array('09', 'Value9', 'No9'),
array('10', 'Value10', 'No10'),
array('11', 'Value11', 'No11'),
array('12', 'Value12', 'No12')
);
The errors I'm getting are:
Notice: Undefined variable: extra in C:\wamp\www\test\class_lib.php on line 47
...and:
Fatal error: Cannot access empty property in C:\wamp\www\test\class_lib.php on line 47
Here's the full class_lib.php file if needed: http://pastebin.com/7XRjDKVU
...and the index.php: http://pastebin.com/yHBYpNxd
I hope I've given enough information there - I'd appreciate any help.