I was wondering if it is possible to have a general system function that checks for a value and if it doesn't exist return another value.
below is what I have come up with however if I use it on a value say $thisvalue but $thisvalue doesn't exist I am getting the error Undefined variable: thisvalue. If thisvalue is empty or null etc below works.
Thanks
public function checkingValue($value = NULL, $empty_return = NULL)
{
if(isset($value))
{
return $value;
}
else
{
return $empty_return;
}
if(!empty($value))
{
return $value;
}
if(!is_null($value))
{
return $value;
}
return $empty_return;
}
isset
and empty
are not functions, they're actually language constructs like switch
and list
and class
.
If you do this:
function my_isset($var) {
return isset($var);
}
isset($undef); // false
my_isset($undef); // Error: Undefined variable: $undef
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.