original_string: public function load_optional_fields() {
          global $DB;
          foreach ($this->optional_fields as $field=>$default) {
              if (property_exists($this, $field)) {
                  continue;
              }
              if (empty($this->id)) {
                  $this->$field = $default;
              } else {
                  $this->$field = $DB->get_field($this->table, $field, array('id', $this->id));
              }
          }
      }
code: public function load_optional_fields() {
          global $DB;
          foreach ($this->optional_fields as $field=>$default) {
              if (property_exists($this, $field)) {
                  continue;
              }
              if (empty($this->id)) {
                  $this->$field = $default;
              } else {
                  $this->$field = $DB->get_field($this->table, $field, array('id', $this->id));
              }
          }
      }
code_tokens: public function load_optional_fields ( ) { global $ DB ; foreach ( $ this -> optional_fields as $ field => $ default ) { if ( property_exists ( $ this , $ field ) ) { continue ; } if ( empty ( $ this -> id ) ) { $ this -> $ field = $ default ; } else { $ this -> $ field = $ DB -> get_field ( $ this -> table , $ field , array ( 'id' , $ this -> id ) ) ; } } }
docstring: Makes sure all the optional fields are loaded.
  
  If id present (==instance exists in db) fetches data from db.
  Defaults are used for new instances.
docstring_tokens: Makes sure all the optional fields are loaded .