ajsie
ajsie

Reputation: 79686

check if a variable is of type mysqli object?

how do i check if a variable is of a type mysqli object?

Upvotes: 16

Views: 10632

Answers (5)

pgk
pgk

Reputation: 1477

Тhe decision of Gumbo works, but in this case must check if $var is instance of mysqli_result, i.e.

$var instanceof mysqli_result;
is_a($var, 'mysqli_result');
get_class($var) == 'mysqli_result';

Upvotes: 9

zombat
zombat

Reputation: 94147

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.

Upvotes: 3

Gumbo
Gumbo

Reputation: 655219

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'

Upvotes: 34

sidereal
sidereal

Reputation: 1120

http://www.php.net/get_class

Upvotes: 2

AJ.
AJ.

Reputation: 28174

Take a look at get_class

Upvotes: 1

Related Questions