1

This error suddenly occurred when Pressflow was added to our Drupal installation. It is coming from a custom module that, prior to Pressflow seemed to work fine. After the addition of Pressflow, running Drush causes this error to display on screen.

The function that is identified as the source of the error looks like this:

function user_search_location_get(&$user) {
  if (count($user->user_location_pref)) {  // This line is causing the error.
    return $user->user_location_pref;
  }

  // …
}

The error message is the following:

WD php: Notice: Undefined property: stdClass::$user_location_pref in user_search_location_get()

apaderno
  • 28,547
  • 16
  • 75
  • 90
sea26.2
  • 376
  • 1
  • 5
  • 23

1 Answers1

2

Short answer, in your custom module, you should check if that property exists before you count it. That, or make sure the $user object has that property before you use it.

if (isset($user->user_location_pref) && count($user->user_locaion_pref) > 0) {
  return $user->user_locaion_pref;
}

While it is a little more work, when you start developing with notices turned on, you will find errors in your code that otherwise would have not appeared till later, and would have been more difficult to track down.

In your previous environment or install, the PHP error reporting was probably set to not show notices. While I recommend keeping notices on and making your code work with them, you can turn them off through the Drupal 7 UI. Configuration -> Development -> Logging and Errors. Then set the value to 'Errors and Warnings' ... Otherwise, you can set your error reporting level in your php.ini to report all except notices.

Note that Drupal 6 did not force notice reporting on, while Drupal 7 does. That prompts this type of question a lot.

If this is your only notice issue though, it makes more sense to just correct your custom module.

Coder1
  • 13,139
  • 15
  • 59
  • 89
  • I think you're onto the real issue. However, this all happened in Drupal 6; with one wrinkle - the errors did not become apparent until Pressflow Drupal was installed. So. You gave the methodology to turn on/off in Drupal 7. What about Drupal 6? Also note that these errors are being displayed on screen via Drush. – sea26.2 Dec 14 '11 at 23:33
  • 1
    I think the bottom line is that PHP's error reporting needs to be set to `error_reporting(E_ALL ^ E_NOTICE);` if you want to ignore notices. You can set that in php.ini and restart the web server. Maybe Drupal 6 forced them to be supressed and Pressflow does not? Not sure. – Coder1 Dec 14 '11 at 23:51
  • Yes, Pressflow and Drupal 6 set the error report to a different level. – apaderno Apr 14 '13 at 16:12