title: PHP Class best practices and class structures
body: <p>I'm currently creating a simple CMS for my small website in PHP5. This is my first 'larger' project in PHP. First I'm creating the needed classes that would simplify me the work a little bit, and there I'm stuck. I need your opinions about the following function inside my <code>UserInfo</code> class:</p>
  
  <pre><code>public function setUser($id) {
          if(!isset($id)) {
              return false;
          }
  
          session_start();
          $conn = new mysql($_SESSION['DBCONNINFO']);
          $sql = "SELECT
                  usr.ID,
                  usr.USERNAME as TUSERNAME,
                  usr.FIRST_NAME,
                  usr.LAST_NAME,
                  usr.PHONE,
                  usr.MOBILE,
                  usr.EMAIL,
                  usr.ADDITIONAL_INFO,
                  usr.LAST_LOGIN_DATE,
                  usr.USER_GROUP_ID
                  FROM cms_users usr
                  WHERE usr.id = " . $id;
  
          $result = $conn-&gt;query_cust($sql);
          $conn=null;
  
          foreach ($result as $row) {
              $this-&gt;id = $row['usr']['ID'];
              $this-&gt;username = $row['usr']['TUSERNAME'];
              $this-&gt;firstname = $row['usr']['FIRST_NAME'];
              $this-&gt;lastname = $row['usr']['LAST_NAME'];
              $this-&gt;phone = $row['usr']['PHONE'];
              $this-&gt;mobile = $row['usr']['MOBILE'];
              $this-&gt;email = $row['usr']['EMAIL'];
              $this-&gt;additional_info = $row['usr']['ADDITIONAL_INFO'];
              $this-&gt;last_login_date = $row['usr']['LAST_LOGIN_DATE'];
              $this-&gt;user_group = $row['usr']['USER_GROUP_ID'];
          }
  
          return true;
      }  
  </code></pre>
  
  <p>Am I doing it the right way, I'm not talking about the syntax, for now I focus on the class structure, design and best practices - any opinion would be appreciated.</p>
  
  <p>Could I call the <code>session_start()</code>, for example, in the class constructor and use the vars inside it without calling it each time in a function !?</p>
  
  <p>Should I close the DB connection via the <code>close()</code> function or is <code>$conn=null</code> acceptable !?</p>
  
  <p>Is it a bad practice to store the database information in the session class !? If yes, where to store it as a 'global' variable - $_GLOBAL !?</p>
  
  <p>If there is a 'PHP bes practice class structures in 5 minutes for dummies' please notify me :)</p>
  
  <p>Thanks in advance.</p>