need to show user firstname and lastname in search result page I'm very new in drupal, and I have a custom user module where I need to show the user's first name and last name in the search result page. I used some of my code which is throwing a fatal error.

What is wrong with the code I am using?

function somik_user_byline($uid) {
  $cache = &amp;drupal_static(__FUNCTION__, array());
  if (isset($cache[$uid])) {
    return $cache[$uid];
  }

  $account = user_load($uid);
  $byline = $account-&gt;name;

  $first_name = somik_user_profile_field_value($uid, 'field_firstname');
  $last_name = somik_user_profile_field_value($uid, 'field_lastname');

  if ($first_name &amp;&amp; $last_name) {
    $byline = $first_name . ' ' . $last_name;
  }

  $cache[$uid] = $byline;

  return $byline;
}
For your error replace:

&lt;?php print drupal_render(somik_user_byline($user-&gt;uid)) &amp;nbsp .$info_split['date']; ?&gt;


with

&lt;?php print somik_user_byline($user-&gt;uid) . '&amp;nbsp;' . $info_split['date']; ?&gt;


For preprocessing you would use:

/**
 * Process variables for the search result template.
 */
function THEMENAME_preprocess_search_result(&amp;$variables) {
  // Change variables here.
}


There is some more info here http://drupal.org/node/223430
It also links to some other useful related pages.

You need to clear the drupal cache when you add or remove a preprocess function.

Edit:

For your "Fatal error: Can't use function return value in write context"

It is because of this part:

if (!empty(somik_user_byline($user-&gt;uid))) {
  $info['user'] = somik_user_byline($user-&gt;uid);
}


Because you can't pass a function call into the empty() function like that. You need to give it a variable.

Because your somik_user_byline() function is always returning a string you can do this:

if ($name = somik_user_byline($user-&gt;uid)) {
  $info['user'] = name;
}


You can go even further than that still.
Because your function always returns a non-empty string, you can just do this:

$info['user'] = somik_user_byline($user-&gt;uid);


Also, for it to be available in the template you have to add it to the $variables array.

For example, you are setting $info but to have it in the template you have to do

$variables['info'] = $info;


at the end and then $info will be available in your template file.

Also, in this case, $info is already full of other information to remember that this will overwrite whatever was alredy in $info from other modules.

If you want to keep the $info that is already there, but override the $info['user'] and $info['date'] parts, do this:

/**
 * Process the variables for search-result.tpl.php
 */
function somik_preprocess_search_result(&amp;$variables) {
  $result = $variables['result'];

  // Override the user part of the info array.
  $variables['info_split']['user'] = somik_user_byline($result['node']-&gt;uid);
  // Override the date part of the info array.
  if (!empty($result['date'])) {
    $variables['info_split']['date'] = format_date($result['node']-&gt;created, 'short');
  }
  // Re-create the info string with the overridden data.
  $variables['info'] = implode(' - ', $info_split);
}