PHP check for valid function return -


i have code:

$myvariable = somerandomfunction($blah)

the problem somerandomfunction() might return array, object, empty array, boolean value or null.

what if best way check $myvariable has data?

right i'm doing this:

!empty($myvariable )

will cover cases? or maybe should ($myvariable != null && !empty($myvariable ))?

update*

by 'some data' mean true if bool, not empty array, , value other null

var_dump(empty(null)); // returns bool(true) 

empty enough. if boolean no data, check !is_bool. (empty(false) returns true)

or better, use if ($result); should enough.

or call "some data"?

update: need:

php > var_dump(!empty([]));

bool(false)

php > var_dump(!empty(""));

bool(false)

php > var_dump(!empty(false));

bool(false)

php > var_dump(!empty(true));

bool(true)

php > var_dump(!empty(null));

bool(false)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -