Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateTimePlus.php

function 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 357

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal