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!
i have an array of objects. Menu Objects tp be precise. I have a Menu class and a subclass SubMenu that extends menu. (my background is java & c)
however when i iterate an array of both menu and submenu objects i can remove the menu objects ok but i cant remove the submenu objects using an inherited method from the menu class.
You said that MenuWorker extended Menu. In the small piece of code you posted, you had: $menuObj -> getMenuID(). You also said that this function (getMenuID) is part of Menu (i.e. inherited). Therefore you need to access it through $this->getMenuID() and not directly as you did in your code. See what I mean now?
there must be some mixup here. Sorry i dont think i have been as clear as i could have. Here is the outline for my classes (the ones im having troubles with anyways
class Menu {
var $menuID = '';
var $menuName = '';
var $menuClass = '';
function Menu($id, $name, $class){}
function setMenuID($id){}
function setMenuName($name){}
function setMenuClass($class){}
function getMenuID(){}
function getMenuName(){}
function getMenuClass(){}
function toString(){}
.
.
.
.
}
class SubMenu extends Menu {
var $href = '';
var $target = '';
var $parentID = 0;
function SubMenu($id, $pid, $name, $href, $class = '', $target = '_self'){}
function setHref($href){}
function setTarget($target){}
function setParentID($pid){}
function getParentID(){}
function getHref(){}
function getTarget(){}
function toString(){}
.
.
.
.
}
class MenuWorker {
/* array to hold the menu's and submenu's */
var $menuArray = null;
/* boolean value to check for redrawing */
var $redrawMenu = false;
/* count of menus in the array */
var $numMenus = 0;
/*
*
*/
function MenuWorker($array = array()){ }
/* Checks if input is a Menu Object, iff it is then it
* is added to the global menu array.
*
* Returns: True iff the input arg is a menu, after adding it
* to the menu array.
*/
function addMenu($menu){}
/*
* Return the number of menus in the global menu array.
*/
function getNumMenus(){ }
/*
* Returns whether or not the menu needs to be redrawn.
*/
function isRedrawMenu(){ }
/*
* Removes a menu from the global menu array
*/
function removeMenu($menuID){
// code here from previous paste ............
}
.
.
.
.
}
Ok yes, I see what you mean. However I still cannot duplicate your error - see the following code which I just wrote to test out essentially what it is you're doing:
i found one little prob, being i wasnt decrementing the num_elements in array on removal. fixing that solved half of the problem but still getting the error
will have to look some more, your test code works fine
cant see y mine is giving me problems,
probably something simple, will come back to it later and probably find it straight away