Search code examples
phpphp-5.3

PHP, fatal error, php dont "see" object


when i print_r or var_dump object i see all properties of if and when i execute function on it for example $data-link() i got error

Fatal error: Call to a member function link() on a non-object in xyx.php on line 281

public function throwBoxProduct($data,$type = false)
     {
           var_dump($data);
           if($data->category->parent != 0){
                ....
           }
           ......

           <a href="'.$data->link().'" class="product_list_link"></a>
      }

on line 281 code is as follows:

 <a href="'.$data->link().'" class="product_list_link"></a>

var_dump($data) output look like this:

object(Products)#302 (17) { 
    ["sizes"]=> bool(false) ["size"]=> bool(false) ["lay"]=> bool(false) ["lays"]=> bool(false) ["logo"]=> NULL 
    ["categories"]=> array(0) { } ["_new":"CActiveRecord":private]=> bool(false)
    ["_attributes":"CActiveRecord":private]=> array(32) { ["id"]=> string(3) "321" ["category_id"]=> string(2) "15" 
    ["sizes_id"]=> string(0) "" ["title"]=> string(15) "Far" ["intro"]=> string(0) "
}

Solution

  • Your $data is NULL (or something other than object), that's why you are getting this error. First make sure you have properly set $data to Products object