1
rlankford
Easy Developer Question
  • 2007/2/6 14:27

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


OK, I have the following code in a module:

$member_handler = &xoops_gethandler'member' );
        
$user = &$member_handler->getUser$userid );

 {
line 882}       if ( is_object$user ) AND $user->getVar('uname') != "") { //whatever }


When a user ID that doesn't exist in the user table is passed as $userid, I get the following error:

Quote:

Fatal error: Call to undefined function: getvar() in C:\Program Files\xampp\htdocs\xoops\modules\moduleName\include\functions.php on line 822


How can I correctly handle this situation so that an error doesn't stop the page whenever an invalid user is passed? If the user isn't valid, I'd simply like to return the anonymous user:

return $GLOBALS['xoopsConfig']['anonymous'];


But how do I test for the existence of userid without generating an error and stopping the page from working?

Thanks in advance!

2
vaughan
Re: Easy Developer Question
  • 2007/2/6 15:20

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


you can use

if (is_object($xoopsUser)) {.....

but remember to make sure $xoopsUser is declared globally with global $xoopsUser;

the above will then check if the user is registered or anonymous.

not entirely sure what you want to achieve tho..

3
rlankford
Re: Easy Developer Question
  • 2007/2/6 15:37

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


Thanks for the reply. I don't think I made myself clear though. If I understand your note, the #xoopsUser object is a global object that refers to the person currently logged in to the site. My situation is a little different. I am showing a page of information that has an author associated with that page. Sometimes, people get deleted from my site on purpose (they leave the company). When generating this page, the user id from the database still points to a user that no longer appears in the users table. What I need is a way to capture/test this scenario so that I can return an anonymous author for the content.

As it stands right now, any attempt that I make to check for the author's validity results in error, which stops the page's generation. I suppose I could always write a dedicated query to ask the user's table for the presence of a particular user id, but I'm betting that there is a simple and obvious thing here that I'm just overlooking.

Thanks for the response!

4
vaughan
Re: Easy Developer Question
  • 2007/2/6 15:59

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


ahhh ok.. i see what you're after..

not entirely sure on how to check tho.. my knowledge isn't great.

if the $userid contains a value?? try echo $user; after $user = &$member_handler->getUser($userid);

see if it displays a value.

then possibly you could use if (empty($user)) and then set the $userid to '0' which would be anonymous (i think)

i wish i was more experienced to be able to help you, but i'm just a beginner..

5
Dave_L
Re: Easy Developer Question
  • 2007/2/6 17:29

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


The error message refers to line "822", but the line displayed is labelled "882". Is that just a typo you made in the post?

Looking at the code in kernel/member.php and kernel/user.php, I would expect $user to have boolean value "false" for this case, so your is_object() check "should" work.

I would follow vaughan's suggestion, but instead of "echo $user;", use "var_dump('user', $user);", which will give you more information.

Bu the way, what's your XOOPS version?

6
rlankford
Re: Easy Developer Question
  • 2007/2/6 18:11

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


Thanks for the reply!

My XOOPS version is 2.0.16. That was a typo, I was trying to call out the appropriate line that caused the error message.

A print_r($user) yields the following:
Quote:

stdClass Object ( [vars] => )


is_Object returns true, which isn't helping me any. Anyway, this is hokey, but here's what I did to get around this:
if ( is_object$user ) AND (count(get_object_vars($user)) > 1)) { //whatever 
}


When a real user is returned, the count statement yields a number of 10. When it's passed a removed user, it returns 1.

It seems to be working at the moment, but I'm sure they're are a dozen ways to do it better!

Login

Who's Online

456 user(s) are online (372 user(s) are browsing Support Forums)


Members: 0


Guests: 456


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits