Page 1 of 1

Call to a member function get_type() on a non-object

Posted: Fri Dec 18, 2009 1:34 pm
by Alaskan57
I'm fairly new to Object Oriented PHP Programming, so I wanted to try out a simple program (listed in the large code section). I got it to work and I decided to use it in a wordpress project. Before porting over, there was no issue. However, when I moved over, my links class starting acting weird and I have no idea why it would only error when I simply changed the directory structure.

This is the line that's calling the class that's producing the error in my display page in my header.php wordpress file:

Code: Select all

writeLink('home', '<img src="'.get_bloginfo('template_directory').'/images/hometab.gif" alt="Home Tab" border="0" width="106" height="34" />').'</li><li>';
Here are my class and function, it errors out over line 51:

Code: Select all

class hyperlink{
    private $url; //Location in the directory; pass value in relation to parent directory.
    private $name; //Name of the link you want to appear in the page.
    private $type; //Type of link (used for styles).  Types are: navlink, pagelink, [otherlink]
    private $target; //Where the page should go. Types are: _blank, _parent, _self, _top, [other]
    private $ATTtitle; //Gives a rollover dialogue box to tell about the link.
    
    function set_url($new_url){
        $this->url = $new_url;
    }
    function set_name($new_name){
        $this->name = $new_name;
    }
    function set_type($new_type){
        $this->type = $new_type;
    }
    function set_target($new_target){
        $this->target = $new_target;
    }
    function set_ATTtitle($new_target){
        $this->ATTtitle = $new_target;
    }
    function get_url(){
        return $this->url;
    }
    function get_name(){
        return $this->name;
    }
    function get_type(){
        return $this->type;
    }
    function get_target(){
        return $this->target;
    }
    function get_ATTtitle(){
        return $this->ATTtitle;
    }
    
    function __construct($link_url,$link_name){
        $this->url = $link_url;
        $this->name = $link_name;
    }
}
 
$home_HL = new hyperlink("home","home");
$home_HL->set_ATTtitle('My Homepage');
 
function writeLink($title,$obj=NULL,$ATTtitle=NULL,$class=NULL,$anchor=NULL,$target=NULL){
    $title = strtolower($title).'_HL';
    $obj = empty($obj) ? $GLOBALS[$title]->get_name() : $obj;
    if(!is_null($GLOBALS[$title]->get_type()) && empty($class)){
        $class = $GLOBALS[$title]->get_type();
    }
    if(!is_null($GLOBALS[$title]->get_ATTtitle()) && empty($ATTtitle)){
        $ATTtitle = $GLOBALS[$title]->get_ATTtitle();
    }
    if(!is_null($GLOBALS[$title]->get_target()) && empty($target)){
        $target = $GLOBALS[$title]->get_target();
    }
    if(!empty($ATTtitle)){
        $ATTtitle = " title='$ATTtitle'";   
    }
    if(!empty($class)){
        $class = " class='$class'";
    }
    if(!empty($anchor)){
        $anchor = "#$anchor";
    }
    if(!empty($target)){
        $target = " target='$target'";
    }
    
    return "<a href='".$GLOBALS[$title]->get_url().$anchor."'$ATTtitle$class$target>".$obj."</a>";
}
Anybody know why there would be a problem? All I did was move directories? Thanks in advance!