/** * Populates all fields according to the string values. */ public function deserializeFromString($obj_str) { if (!$obj_str or strlen($obj_str) == 0) { // no string to deserialize fomr return; } $name_value_pairs = explode(myBaseObject::FIELD_SEPARATOR, $obj_str); foreach ($name_value_pairs as $pair) { $tokens = explode(myBaseObject::FIELD_EQUAL, $pair); $tok_count = count($tokens); if ($tok_count == 0) { continue; } elseif ($tok_count == 1) { $name = $tokens[0]; $value = NULL; } elseif ($tok_count == 2) { $name = $tokens[0]; $value = $tokens[1]; } else { throw Exception("encode/decode didn't work well - there are '=' characters within the name or the value of a serialized field"); } // echo $name . "=" . $value ."<br>"; // first token is the name of the field, second token is the value $this->setByName($name, myBaseObject::decode($value)); } }