API page: https://api.drupal.org/api/drupal/modules!user!user.module/function/user...
The $roles parameter is optional. It would be fair to assume that if omitted, you get data for all roles -- after all, this is how lots of Drupal functions work.
That is however not the case. You get nothing. I'm not even sure why the param is optional, as you can nothing without it. It might be a remnant from when this function would have had a $reset parameter too.
Anyway, we probably shouldn't change it on D7 now, so we should change the docs to say that there's no point calling it without $roles.
Comments
Comment #1
jhodgdonI don't see any documentation there saying $roles is optional? I see it has a default value of array(), but there is no documentation saying $roles is optional or that if you pass in nothing you get all the roles. So I don't see a problem in the docs here.
Comment #2
joachim commented> I see it has a default value of array(),
That means it's optional!
Comment #3
jhodgdonAgreed, the default means it is optional. However, the docs do not say it's optional, so I'm not sure what we can do. If you want to make this a pure 8.x and user.module issue instead of documentation, you could lobby to have that default removed.
Comment #4
joachim commented8.x has the default removed :)
My point is that what happened to me could easily happen to other developers: call the function with no parameter, assuming that'll get you data for all roles because that's how Drupal tends to work. Get nothing back. Scratch head, read code.
Could we just add a note to say there parameter being optional is a bug, and it is in fact necessary?
Comment #5
jhodgdonOK. :) Make a patch?
Comment #6
-enzo- commentedI just did an small patch , please review
Comment #7
joachim commentedThis issue is just about fixing the documentation.
Unfortunately, we can't change the return value of an API function at this point in the development of 7.x.
Comment #8
lauriiiHere's a patch for the comment.
Comment #9
jhodgdonThanks for the patch!
We need to have all of the lines of documentation wrapped into a paragraph, so that each line is close to 80 characters without going over.
Comment #10
lauriiiNow with fixed line lenghts
Comment #11
jhodgdonPlease move the last sentence up to the previous line. Thanks! Also... can we not use the non-word "param" in the documentation text? Just say "If $roles is a non-empty array...". Thanks!
Comment #12
lauriiiMaybe now!
Comment #13
lauriiiComment #15
jhodgdonThanks! This one looks good to me. I'll get it committed sometime soon.
Comment #16
jhodgdonThanks again! Committed to 7.x.