{"record":{"id":"90cc26c0052f4e16","repo":"phacility/phabricator","slug":"unable-to-construct-a-date-value-from-value-of-typ","errorCode":null,"errorMessage":"Unable to construct a date value from value of type \"%s\".","messagePattern":"Unable to construct a date value from value of type \"(.+?)\"\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/view/form/control/AphrontFormDateControlValue.php","lineNumber":146,"sourceCode":"      $value->valueDate,\n      $value->valueTime);\n\n    if ($formatted) {\n      list($value->valueDate, $value->valueTime) = $formatted;\n    }\n\n    $value->valueEnabled = idx($dictionary, 'e');\n\n    return $value;\n  }\n\n  public static function newFromWild(PhabricatorUser $viewer, $wild) {\n    if (is_array($wild)) {\n      return self::newFromDictionary($viewer, $wild);\n    } else if (is_numeric($wild)) {\n      return self::newFromEpoch($viewer, $wild);\n    } else {\n      throw new Exception(\n        pht(\n          'Unable to construct a date value from value of type \"%s\".',\n          gettype($wild)));\n    }\n  }\n\n  public function getDictionary() {\n    return array(\n      'd' => $this->valueDate,\n      't' => $this->valueTime,\n      'e' => $this->valueEnabled,\n    );\n  }\n\n  public function getValueAsFormat($format) {\n    return phabricator_format_local_time(\n      $this->getEpoch(),\n      $this->viewer,","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/view/form/control/AphrontFormDateControlValue.php#L128-L164","documentation":"AphrontFormDateControlValue::newFromWild() is the loose constructor used when a date arrives from storage or an untrusted source. It accepts exactly two shapes: an array dictionary (as produced by the date control request reader, keys like 'd'/'t'/'e') or anything is_numeric() (an epoch or numeric string). Any other value — a formatted string like '2026-01-01', null, a boolean, an object — throws, with the PHP type name included in the message.","triggerScenarios":"Passing a human-readable date string ('2026-01-01', 'Jan 1 2026'), null, false, or an object to newFromWild($viewer, $value).","commonSituations":"Custom storage or Conduit endpoints that keep dates as formatted strings; migrating legacy string date columns into date controls; default values pulled from config where the value is null.","solutions":["Convert strings to epochs first: newFromEpoch($viewer, strtotime($date_string)).","If the value comes from the date control form submission, use newFromRequest($request, $key) or newFromDictionary() instead of newFromWild().","Validate or coerce unknown input (is_array / is_numeric) before calling newFromWild()."],"exampleFix":"// before\n$value = AphrontFormDateControlValue::newFromWild($viewer, '2026-01-01');\n\n// after\n$value = AphrontFormDateControlValue::newFromEpoch(\n  $viewer,\n  strtotime('2026-01-01'));","handlingStrategy":"validation","validationCode":"if (!is_array($raw) && !is_numeric($raw)) {\n  $raw = strtotime((string)$raw); // or reject the input explicitly\n}\n$value = AphrontFormDateControlValue::newFromWild($viewer, $raw);","typeGuard":"function isWildDateInput($value) {\n  return is_array($value) || is_numeric($value);\n}","tryCatchPattern":"try {\n  $value = AphrontFormDateControlValue::newFromWild($viewer, $raw);\n} catch (Exception $ex) {\n  // Unparseable stored value: fall back to the current epoch.\n  $value = AphrontFormDateControlValue::newFromEpoch(\n    $viewer,\n    PhabricatorTime::getNow());\n}","preventionTips":["Store and pass epochs (integers), never formatted date strings.","Remember is_numeric() rejects booleans: true and false also throw.","Prefer the typed constructors (newFromEpoch, newFromDictionary, newFromRequest) over newFromWild()."],"tags":["php","phabricator","date-control","input-validation"],"backgroundTag":"invalid-date-input","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}