undefined offset 0

Login or register to post comments
1 reply [Last post]
Offline
Joined: 12/10/2008

Hi,

I am trying to debug this and I keep getting an error in line 24.

I am guessing that the ReferalArray doesn't exist, that Line 21 is creating NULL.

Is there a way that I can do a check before Line24 if it exists and otherwise assign a default value or skip the section altogether?

Thanks.

Line 19:    $this->objUser = unserialize($_SESSION['User']);
Line 20:   
Line 21:    $ReferalArray = User::LoadArrayByUserAsAllies($this->objUser->Id);
Line 22:   
Line 23:    $this->lblReferal = new QLabel($this);
Line 24:    $this->lblReferal->Text = $ReferalArray[0]->FullName;

Offline
Joined: 05/15/2009

Hi,

You can do it like this:

$ReferalArray = User::LoadArrayByUserAsAllies($this->objUser->Id);

$this->lblReferal = new QLabel($this);
if ($ReferalArray) {
   $this->lblReferal->Text = $ReferalArray[0]->FullName;
} else {
   $this->lblReferal->Text = "Some default";
}