how do i check if a variable is of a type mysqli object?
+5
A:
Try the instanceof operator, the is_a function or the get_class function:
$var instanceof MySQLi
is_a($var, 'mysqli')
is_object($var) && get_class($var) == 'mysqli'
Gumbo
2010-02-04 20:54:55
weird...none of those worked...and im sure its a mysqli object cause i do a mysqli_fetch_assoc on it and it works..but when i add a if(is_a($var, 'mysqli') nothing is outputted. nor when i use the other 2..
weng
2010-02-04 22:15:04
@noname: If your doing `mysqli_fetch_assoc($var)` then `$var` is not a MySQLi object but a MySQLi result resource (see http://php.net/resource). That’s something different.
Gumbo
2010-02-05 06:40:28
+2
A:
You'll probably want the instanceof operator.
It will work for derived classes as well, in the odd case that you extending or building your own wrappers.
zombat
2010-02-04 20:54:56