Yii Framework Forum: Trying To Get Property Of Non-Object - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Trying To Get Property Of Non-Object

#1 User is offline   MaziTizeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 12-June 12
  • Location:U.A.E

Posted 29 October 2012 - 10:19 AM

Hi,
this is my sample code,

public function getIncome($regid){
   $commissionbank = new CommissionBank;
   $criteria=new CDbCriteria;
   $criteria->condition = 'ReceiverID =:regID';
   $criteria->params=array(':regID'=>$regid);
   $criteria->select = 'sum(DepositeAmount) as amount';
   $criteria->group = 'ReceiverID';
   $income = $commissionbank->model()->find($criteria);
   return $income->amount;
}


this function is working properly before i updated my PHP version , after that when result is Null i am getting error as: " Trying to get property of non-object "

so , what is solution for this problem, the same way i am using in so many function.
0

#2 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 29 October 2012 - 11:29 AM

Check if $income is null

$amount = 0;

if ($income)
{
    $amount = $income->amount;
}

return $amount;

//OR

return ($income) ? $income->amount : 0;


0

#3 User is offline   MaziTizeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 12-June 12
  • Location:U.A.E

Posted 30 October 2012 - 02:20 AM

thanks , but why before update my version it was working properly?
if i check that return value is null or not , it's OK , but i should do it iin all my function?
any other idea?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users