public static function instantiate($record) { // Check if $record exists and is an array // $object = new User(); // $object = new self; $object = new Photograph(); // Short Method foreach ($record as $attribute => $value) { // Why check ??? if ($object->has_attribute($attribute)) { // See the syntax of attribute here with $ - dynamic variable $object->{$attribute} = $value; } // return $object; -- ThIS IS WRONG WRONG } //BE VERY VERY CAREUL WHERE U R RETURNING YOUR OBJECT // HERE I LOST 1 HOUR BCOZ OF THAT MISTAKE return $object; // Long method // not required here ---> $record = User::find_by_id(1); // $object->username = $record['username']; // $object->password = $record['password']; // $object->first_name = $record['first_name']; // $object->last_name = $record['last_name']; // $object->id = $record['id']; }