Remove deprecated defaults() function
This commit is contained in:
parent
8b836189d4
commit
f65ebb937c
41
boot.php
41
boot.php
|
@ -322,47 +322,6 @@ function get_app()
|
|||
return BaseObject::getApp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the provided variable value if it exists and is truthy or the provided
|
||||
* default value instead.
|
||||
*
|
||||
* Works with initialized variables and potentially uninitialized array keys
|
||||
*
|
||||
* Usages:
|
||||
* - defaults($var, $default)
|
||||
* - defaults($array, 'key', $default)
|
||||
*
|
||||
* @param array $args
|
||||
* @brief Returns a defaut value if the provided variable or array key is falsy
|
||||
* @return mixed
|
||||
* @deprecated since version 2019.06, use native coalesce operator (??) instead
|
||||
*/
|
||||
function defaults(...$args)
|
||||
{
|
||||
if (count($args) < 2) {
|
||||
throw new BadFunctionCallException('defaults() requires at least 2 parameters');
|
||||
}
|
||||
if (count($args) > 3) {
|
||||
throw new BadFunctionCallException('defaults() cannot use more than 3 parameters');
|
||||
}
|
||||
if (count($args) === 3 && is_null($args[1])) {
|
||||
throw new BadFunctionCallException('defaults($arr, $key, $def) $key is null');
|
||||
}
|
||||
|
||||
// The default value always is the last argument
|
||||
$return = array_pop($args);
|
||||
|
||||
if (count($args) == 2 && is_array($args[0]) && !empty($args[0][$args[1]])) {
|
||||
$return = $args[0][$args[1]];
|
||||
}
|
||||
|
||||
if (count($args) == 1 && !empty($args[0])) {
|
||||
$return = $args[0];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Used to end the current process, after saving session state.
|
||||
* @deprecated
|
||||
|
|
Loading…
Reference in New Issue
Block a user