<?php
class User {
private $id;
private $username;
public function __construct($id = null) {
$this->id = $id;
if (!is_null($this->id)) {
$this->load();
}
}
public function load() {
}
}
?>
In the ‘load’ method I am going to load all the information from the current user (id) But I wonder how is the best way to load all info. I could grab all data and then just assign all private variables, but I assume there must be another “cheaper” way to get all the data so I can use as such
$this->variable;
And not have to ASSIGN every single data row, I select in the load method. How?
I am assuming the following:
You can retrieve information for your user in an associative array:
$user = array('name' => 'John', 'age' => 20);Then perhaps using variables variables could be a viable solution in your
load()method: