Returning objects in php

Posted by user220201 on Stack Overflow See other posts from Stack Overflow or by user220201
Published on 2010-05-04T13:55:33Z Indexed on 2010/05/04 13:58 UTC
Read the original article Hit count: 189

Filed under:
|

I see similar questions asked but I seem to have problem with more basic stuff than were asked. How to declare a variable in php? My specific problem is I have a function that reads a DB table and returns the record (only one) as an object.

class User{
   public $uid;
   public $name;
   public $status;
}

function GetUserInfo($uid)
{
   // Query DB

   $userObj = new User();

   // convert the result into the User object.

   var_dump($userObj);   
   return $userObj;
}

// In another file I call the above function.

....

$newuser = GetUserInfo($uid);

var_dump($newuser);

What is the problem here, I cannot understand. Essentially the var_dump() in the function GetUserInfo() works fine. The var_dump() outside after the call to GetUserInfo() does not work.

Thanks for any help.

  • S

© Stack Overflow or respective owner

Related posts about php

Related posts about objects