function DateTimePlus::__call
Same name in other branches
- 9 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::__call()
- 8.9.x core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::__call()
- 11.x core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::__call()
Implements the magic __call method.
Passes through all unknown calls onto the DateTime object.
Parameters
string $method: The method to call on the decorated object.
array $args: Call arguments.
Return value
mixed The return value from the method on the decorated object. If the proxied method call returns a DateTime object, then return the original DateTimePlus object, which allows function chaining to work properly. Otherwise, the value from the proxied method call is returned.
Throws
\Exception Thrown when the DateTime object is not set.
\BadMethodCallException Thrown when there is no corresponding method on the DateTime object to call.
File
-
core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php, line 351
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
public function __call($method, array $args) {
// @todo consider using assert() as per https://www.drupal.org/node/2451793.
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()', static::class, $method));
}
$result = call_user_func_array([
$this->dateTimeObject,
$method,
], $args);
return $result === $this->dateTimeObject ? $this : $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.