how do i check if a variable is of a type mysqli object?
我如何检查变量是否是mysqli类型的对象?
5 个解决方案
#1
28
Try the instanceof
operator, the is_a
function or the get_class
function:
尝试使用instanceof运算符,is_a函数或get_class函数:
$var instanceof MySQLi
is_a($var, 'mysqli')
is_object($var) && get_class($var) == 'mysqli'
#2
6
Тhe decision of Gumbo works, but in this case must check if $var
is instance of mysqli_result
, i.e.
Gumbo的决定有效,但在这种情况下必须检查$ var是否是mysqli_result的实例,即
$var instanceof mysqli_result;
is_a($var, 'mysqli_result');
get_class($var) == 'mysqli_result';
#3
3
You'll probably want the instanceof operator.
你可能想要instanceof运算符。
It will work for derived classes as well, in the odd case that you extending or building your own wrappers.
它也适用于派生类,在奇怪的情况下,您可以扩展或构建自己的包装器。
#1
28
Try the instanceof
operator, the is_a
function or the get_class
function:
尝试使用instanceof运算符,is_a函数或get_class函数:
$var instanceof MySQLi
is_a($var, 'mysqli')
is_object($var) && get_class($var) == 'mysqli'
#2
6
Тhe decision of Gumbo works, but in this case must check if $var
is instance of mysqli_result
, i.e.
Gumbo的决定有效,但在这种情况下必须检查$ var是否是mysqli_result的实例,即
$var instanceof mysqli_result;
is_a($var, 'mysqli_result');
get_class($var) == 'mysqli_result';
#3
3
You'll probably want the instanceof operator.
你可能想要instanceof运算符。
It will work for derived classes as well, in the odd case that you extending or building your own wrappers.
它也适用于派生类,在奇怪的情况下,您可以扩展或构建自己的包装器。