Check if the variable passed as an argument is set

masterlogo

New Member
I want to check if a variable called $smth is blank ( i mean empty space ), and i also want to check if it is set using the function i defined below:\[code\]function is_blank($var){ $var = trim($var); if( $var == '' ){ return true; } else { return false; }}\[/code\]The problem is i can't find a way to check if variable $smth is set, inside is_blank() function. The following code solves my problem but uses two functions:\[code\]if( !isset($smth) || is_blank($smth) ){ // code;}\[/code\]If i use an undeclared variable as an argument for a function it says:\[code\]if( is_blank($smth) ){ //code;}Undefined variable: smth in D:\Www\www\project\code.php on line 41\[/code\]Do you have a solution for this ?Thank you very much,Alex from Romania** !! LATER EDIT !! **This is what i came up with:\[code\]function is_blank(&$var){ if( !isset($var) ){ return true; } else { if( is_string($var) && trim($var) == '' ){ return true; } else { return false; } } }\[/code\]and works like a charm, thank you very much for the idea nikic.
 
Back
Top