diff -u b/core/lib/Drupal/Component/Datetime/DateTimePlus.php b/core/lib/Drupal/Component/Datetime/DateTimePlus.php --- b/core/lib/Drupal/Component/Datetime/DateTimePlus.php +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php @@ -93,6 +93,8 @@ /** * The DateTime object. + * + * @var \DateTime */ protected $dateTimeObject = NULL; @@ -282,16 +284,30 @@ } /** - * Passes through all unknown calls onto the DateTime object. + * {@inheritdoc} */ public function __call($method, $args) { + if (!isset($this->dateTimeObject)) { + throw new Exception('DateTime object not set.'); + } + if (!method_exists($this->dateTimeObject, $method)) { + throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method)); + } return call_user_func_array(array($this->dateTimeObject, $method), $args); } /** - * PHP magic __clone() method. - * - * Deep-clones the DateTime object we're wrapping. + * {@inheritdoc} + */ + public static function __callStatic($method, $args) { + if (!method_exists('\DateTime', $method)) { + throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $method)); + } + return call_user_func_array(array('\DateTime', $method), $args); + } + + /** + * {@inheritdoc} */ public function __clone() { $this->dateTimeObject = clone($this->dateTimeObject); @@ -370,11 +386,7 @@ * @see http://us3.php.net/manual/en/time.getlasterrors.php */ public function checkErrors() { - if (!isset($this->dateTimeObject)) { - return; - } - - $errors = $this->dateTimeObject->getLastErrors(); + $errors = self::getLastErrors(); if (!empty($errors['errors'])) { $this->errors += $errors['errors']; }