/** * Call a global function or class method (if exists) or callable with specified arguments. * * @param string|array|\Closure $what A global function name or class method (if exists) or callable * @param mixed,... $arguments Arguments to pass to the global function * * @return mixed */ public static function this($what, ...$arguments) { if (is_string($what)) { return static::handle($what, null, null, ...$arguments); } if (is_array($what)) { return static::handle(getLastArrayElement($what), getFirstArrayElement($what), false, ...$arguments); } if ($what instanceof \Closure) { return $what(...$arguments); } throw InvalidArgumentException::create()->setMessage('Invalid call requested (got "%s" with parameters "%s").', var_export($what, true), var_export($arguments, true)); }
/** * @param string $name * * @return null|StopwatchEvent */ protected function getStopwatchEventLast($name) { if ($this->hasStopwatchEventSet($name)) { return getLastArrayElement($this->stopwatchEventSet[$name]); } return null; }
public function testGetArrayLastOnNonArrayAccess() { static::assertNull(getLastArrayElement('not-iterable')); }