CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Mar 2007
    Posts
    13

    Re: PHP drives me nuts -> Call to a member function on a non-object

    Hello friends,

    I have problems with this:

    MenuItem.class.php:
    Code:
    <?php
    	class MenuItem {
    		
    		var $label;
    		var $href;
    		var $target;
    		
    		function MenuItem($label="", $href="", $target="") {
    			$this->label = $label;
    			$this->href = $href;
    			$this->target = $target;
    		}
    		
    		function isEmpty() {
    			return $this->label == "" && $this->href == "" && $this->target == "";
    		}
    		
    		function toString() {
    			return "<td><a href='".$this->href."' target='".$this->target."'>".$this->label."</a></td>";
    		}
    		
    	}
    ?>
    MenuBar.class.php:
    Code:
    <?php
    include_once("MenuItem.class.php");
    
    class MenuBar {
    	
    	var $items;
    	
    	function MenuBar() {
    		$this->items = array(new MenuItem());
    	}
    	
    	function add($item) {
    		if ($this->items[0]->isEmpty()) {
    			$this->items[0] = $item;
    		} else {
    			$this->items[count($this->items)] = $item;
    		}
    	}
    	
    	function show() {
    		$me = "<table><tr>";
    		$j = count($this->items);
    		for ($i=0; $i<$j; $i++) {
    			$me .= $this->items[$i]->toString();
    		}
    		$me .= "</tr></table>";
    	}
    	
    }
    ?>
    menu.php:
    Code:
    <?php
    	include_once("../scripts/MenuBar.class.php");
    	
    	$menu = new MenuBar();
    	$menu->add("Google", "http://www.google.co.cr/", "_blank");
    	$menu->show();
    ?>
    The Apache return the follow error:

    Fatal error: Call to a member function on a non-object in /home/iconco/public_html/invent/scripts/MenuBar.class.php on line 25

    Can Helpme??
    Last edited by wilz04; March 29th, 2007 at 12:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured