function _Course::__sleep

4.x _Course.php _Course::__sleep()
5.x _Course.php _Course::__sleep()

This is the magic method __sleep(). PHP will call this method any time this object is being serialized. It is supposed to return an array of all the variables which need to be serialized.

What we are doing in it is skipping any variables which we are not using or which do not need to be serialized. This will greatly reduce the size of the final serialized string.

It may not seem worth it at first, but consider that we may be serializing an entire degree plan, with a dozen groups, each with every course in the catalog. That could easily be 10,000+ courses which get serialized!

Return value

array

File

classes/_Course.php, line 1452

Class

_Course

Code

function __sleep() 
 {
  // This is supposed to return an array with the names
  // of the variables which are supposed to be serialized.

  $arr = array(
    "db_advised_courses_id",
    "db_substitution_id", "db_unassign_transfer_id",
    "db_exclude", "array_index", "db_group_requirement_id", "array_valid_names",
    "data_entry_value",

    "subject_id", "course_num", "course_id", "requirement_type", "catalog_year",
    "min_hours", "max_hours", "repeat_hours", "bool_outdated_sub",

    "bool_taken", "term_id", "section_number", "grade", "hours_awarded", "quality_points",
    "bool_transfer", "institution_id", "institution_name", "course_transfer", "transfer_footnote",
    "bool_substitution", "course_substitution", "substitution_hours",
    "bool_substitution_split", "substitution_footnote", "bool_substitution_new_from_split",

    "min_grade", "specified_repeats", "bool_specified_repeat", "required_on_branch_id",
    "assigned_to_group_id", "assigned_to_semester_num",

    "advised_hours", "bool_selected", "bool_advised_to_take", "bool_use_draft",
    "course_fulfilled_by", "course_list_fulfilled_by",
    "bool_has_been_assigned", "bool_added_course", "group_list_unassigned",

    "display_status", "bool_has_been_displayed", "bool_hide_grade", "bool_ghost_hour",
    "bool_ghost_min_hour",
  );

  // Okay, remove any variables we are not using
  // from the array.
  $rtn = array();
  foreach ($arr as $var) 
   {
    if (isset($this->$var)) // This checks to see if we are using
     { // the variable or not.
      $rtn [] = $var;
    }
  }

  return $rtn;
}