Check if variable is set in function call
I have a little issue:
<?=$this->bs_forms->text_input('last_name','Name', $user->last_name);?>
If the last variable $user, does not exist I currently get some PHP
errors. My solution was this:
<?=$this->bs_forms->text_input('last_name','Last Name', (isset($user))?
$user->last_name : NULL);?>
But that's seems a bit hacky. Is there a better way to do this?
No comments:
Post a Comment