Function won't return value

Discussion in 'PHP' started by Googl, May 3, 2011.

  1. #1
    I have a very simple problem that has left me stuck and I was hoping you might be able to spot the error. This method will echo the value but will not return. Can you help me spot the error. The method works perfectly fine but will not return the value.

    
          public function get_link_id ($permalink){
    		$addition = 'WHERE PERMALINKS LIKE "%'.$permalink.'%"';
    		if ($data = $this->get_data ($this->permalinks_table, '0', '1', $addition)){
    			$link_id = $data[0]['LINK_UNIQUEID'];
    			return $link_id;
    		}else {
    			return false;
    		}
    	}
    PHP:
    External code:
    $cached_uniqueid = $permalinks_obj->get_link_id ($post_perma);
    		echo $cached_uniqueid;
    PHP:
    Thanks...
     
    Googl, May 3, 2011 IP
  2. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Strange, the function should return something in any case. If it does not echo anything, probably the function returned false. Echoing true will print 1 but echoing false does not print anything, not even 0. So its likely that $this->get_data(...) call failed.
     
    ap2010, May 3, 2011 IP
  3. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    PS: try:

    
    echo $cached_uniqueid === false ? "function returned false" : $cached_uniqueid;
    
    PHP:
     
    ap2010, May 3, 2011 IP