Array problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
echobeatz
Forum Newbie
Posts: 1
Joined: Sun Dec 15, 2002 12:48 pm

Array problems

Post 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!
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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]
Post Reply