title: PHP - unable to instantiate objects with data
body: <p>I'm studying PHP and building a simple web app to save\get data from the database. I built a <code>User</code> class and I'm trying to create objects based upon that class and pass the relevant parameters to the constructor. I am able to retrieve data from the db, followed several guides and I still receive an empty array in the front.</p>
  
  <pre><code>class User{
      protected $firstName;
      protected $lastName;
      protected $pass;
  
      function __construct($firstn,$lastn,$upass){
          $this-&gt;firstName = $firstn;
          $this-&gt;lastName = $lastn;
          $this-&gt;pass = $upass;
      }
     function setFname($first){
         $this-&gt;firstName = $first;
     }
     function setLname($last){
         $this-&gt;lastName = $last;
     }
     function setPass($pass){
         $this-&gt;pass = $pass;
     }
  
  }
  </code></pre>
  
  <p>This is the part where I'm creating <code>user</code> objects and push them into the array.</p>
  
  <pre><code>    if($stmt =mysqli_prepare($conn, $getUsersStatement)){
          mysqli_stmt_execute($stmt);
          mysqli_stmt_bind_result($stmt,$first,$last,$pass,$id);
          $resultArray = [];
          while(mysqli_stmt_fetch($stmt)){
  //            $user = new User($first,$last,$pass);
              $user = new User($first,$last,$pass);
              $user-&gt;setFname($first);
              $user-&gt;setLname($last);
              $user-&gt;setPass($pass);
  //                $user-&gt;lastName =$last;
  //                $user-&gt;pass =$pass;
  //            printf ("%s %s %s\n", $first, $last, $pass,$id); //this works and prints the data
              array_push($resultArray,$user);
          }
          /* close statement */
          echo (json_encode($resultArray));
          mysqli_stmt_close($stmt);
      }
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>[{},{},{},{},{},{},{}]
  </code></pre>