Page 1 of 1

Array problems

Posted: Sun Dec 15, 2002 12:48 pm
by echobeatz
Hi,
I'm having problems using array that I cannot figure out at all,
I have a small class, Category, theres two methods(of concern) which are defined as:

Code: Select all

function add($link, $name)
{
    $this->$pages[$link] = $name;
}

function hasPage($page_link)
{
    return !empty($this->$pages[$page_link]);
}
Anyway, I use the class by creating various categories, an extract from that section

Code: Select all

$dev = new Category;
    $dev->catPage("dev");
    $dev->add("bugs", "Bugs List");
    $dev->add("history", "History");
    $dev->add("todolist", "Todo");
    $dev->add("docu", "Documentation");
    $categories['Development'] = $dev;

    $down = new Category;
    $down->catPage("download");
    $categories['Download'] = $down;
Right, now comes my problem, when I try to find out whether a page exists it always returns true, whether or not it is, I done a small test and it seems that when an element does not exist it return 'Documentation'(when working with the Development array element)

Can anybody please help me, thankyou!

Posted: Sun Dec 15, 2002 1:59 pm
by nathus

Code: Select all

function hasPage($page_link) 
{ 
    return !empty($this->$pages[$page_link]); 
}
you have a $ where it shouldn't be. should be $this->pages[$page_link]