PHP is_object() Function

PHP 可用的函数PHP Available Functions

is_object()The function is used to detect whether a variable is an object.

PHP Version Requirements: PHP 4, PHP 5, PHP 7

Syntax

bool is_object ( mixed $var )

Parameter description:

  • $var: The variable to be detected.

Return Value

Returns TRUE if the specified variable is an object, otherwise returns FALSE.

Examples

Examples

<?php function get_subjects($obj_name) { if(!is_object($obj_name)) { return(false); } return($obj_name->subjects); } $obj_name = new stdClass; $obj_name->subjects = Array('Google', 'Example', 'Facebook'); var_dump(get_subjects(NULL)); var_dump(get_subjects($obj_name)); ?>

The output result is:

bool(false)
array(3) {
  [0]=>
  string(6) "Google"
  [1]=>
  string(6) "Example"
  [2]=>
  string(8) "Facebook"
}

PHP 可用的函数PHP Available Functions

Other Extensions