I'm trying to build a class in PHP and for some reason I can't seem to set the class variables properly. Every time I call a function of the class, the variables, which were set by the constructor, are null.
Does anyone have any advice? Here's the code for the constructor and one of the functions that use an object variable:
class comicNavigator{
var $comic_list;
var $cur_comic;
var $last_comic;
var $chapter_list;
var $cur_chapter;
// Initialize our ordered list of existing comics and set the
// current comic.
function comicNavigator ( $list, $cur = null ){
echo $list;
$comic_list = $list;
$last_comic = count( $list ) -1;
if( $cur ){
$index = 0;
foreach( $list as $item ){
if ( $item[4] == $cur ){
$cur_comic = $index;
}
$index++;
}
$cur_comic = $cur;
} else {
$cur_comic = $last_comic;
}
$cur_chapter = substr( $list[$cur_comic][4], 0, strpos( $list[$cur_comic][4], "x" )+1 );
echo "End of Init: ".$comic_list;
}
function nextComic (){
if( $cur_comic == $last_comic ){
return null;
} else {
return $comic_list[$cur_comic+1][4];
}
}
}
For reference, the variable $list is a 2-dimentional array.