I tried to wrap my own function using empty().
The function named is_empty is to check whether a value is empty, if it’s empty, return a specified value. Code is as below.
static public function is_empty($val,$IfEmptyThenReturnValue)
{
if(empty($val))
{
return $IfEmptyThenReturnValue;
}
else
{
return $val;
}
}
And I call this function like this:
$d="it's a value";
echo Common::is_empty($d, "null");
That’s ok. It printed the “it’s a value”.
but if I don’t defined the $d. like below:
echo Common::is_empty($d, "null");
Yes, it will print the “null”.
But it will also print a waring:Notice:
Undefined variable: d in D:\phpwwwroot\test1.php on line 25.
So how to fix this function?
A simple
&to save your life: