Class alt
Fail-safe utilities
To get started, place the following line around top of your code.
use amekusa\plz\alt;
Methods summary
public static
mixed
|
#
null( mixed $X, mixed $Alt )
If $X is null , returns $Alt . Otherwise returns $X
If $X is null , returns $Alt . Otherwise returns $X
Parameters
- $X
- A variable to check
- $Alt
- A fail-safe value
Returns
mixed
$X or $Alt
Example
Demonstration
$var1 = 'Not Null';
$var2 = null;
var_dump( alt::null($var1, 'Null') );
var_dump( alt::null($var2, 'Null') );
string(8) "Not Null"
string(4) "Null"
|
public static
mixed
|
#
false( mixed $X, mixed $Alt )
If $X is falsy, returns $Alt . Otherwise returns $X
If $X is falsy, returns $Alt . Otherwise returns $X
Parameters
- $X
- A variable to check
- $Alt
- A fail-safe value
Returns
mixed
$X or $Alt
Example
Demonstration
$var1 = 'Truthy';
$var2 = '';
var_dump( alt::false($var1, 'Falsy') );
var_dump( alt::false($var2, 'Falsy') );
string(6) "Truthy"
string(5) "Falsy"
|