超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<is_numericis_real>
Last updated: Fri, 22 Jun 2007

is_object

(PHP 3, PHP 4 , PHP 5)

is_object -- 检测变量是否是一个对象

描述

bool is_object ( mixed var)

如果 var 是一个 object 则返回 TRUE,否则返回 FALSE

参见 is_bool()is_int()is_integer()is_float()is_string()is_array()




add a note add a note User Contributed Notes
is_object
lbjay can be emailed at reallywow dot com
03-May-2003 03:18
I'm not even sure how to articulate this, so I'm going to just include test code. Maybe someone else will someday wonder the same thing.

<?
   error_reporting(E_ALL);
   class testParent
   {
       var $child;

       function testParent()
       {
           $this->child = new testChild();
       }
   }

   class testChild
   {
     function testChild()
       {
       }
   }

  $parent = new testParent();
   $parent2 = 'foobar';

   print join(',', Array(
       is_object($parent) ? 'yes' : 'no',
      is_object($parent->child) ? 'yes' : 'no',
       is_object($parent2) ? 'yes' : 'no',
       is_object($parent2->child) ? 'yes' : 'no'
  ));

?>

This prints "yes,yes,no,no". Basically this shows that you can use is_object to test if the child object is an object without worrying about an error if the parent object isn't an object either.

<is_numericis_real>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22