Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Testing for object type


Testing for object type

Reply
  #1 (permalink)  
Old 09-22-09, 12:11 PM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
Testing for object type

I knows there is a way to do this but I am not thinking of the syntax right away and my first search attempts did not turn it up for me.

I want to test for user defined object

for instance

PHP Code:

class foo {

   public function 
__construct(){
       
$this->text "foobar";
   }
}

// test if something is foo 
I want to check a variable to see if it is the user defined object foo. What is the syntax to do this again?
Reply With Quote
  #2 (permalink)  
Old 09-22-09, 12:15 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

if ($bar instanceof foo)

{
    
/* Do something */

... PHP: Type Operators - Manual
Reply With Quote
The Following User Says Thank You to Nico For This Useful Post:
carters-site (09-22-09)
  #3 (permalink)  
Old 09-22-09, 01:27 PM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
Thanks Nico.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and MSSQL tutorials? scott2500uk C/C++ 8 05-11-09 02:33 AM
Default value for the Datetime data type... Clark_Kent Database 2 08-09-06 07:40 AM
Include problem in C bkbenson C/C++ 4 02-08-05 04:24 AM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM
Innodb type Table (Foreign key) zoni PHP 1 05-04-04 03:35 AM


All times are GMT -5. The time now is 08:00 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.