Share on Google+Share on Google+

PHP Instanceof Operator

Advertisement
In this tutorial we will study about instanceof operator, instanceof operator checks that a variable is instantiated object of a certain class or not. Examples in this tutorial will make it more clear.

Type Operators:

This is another kind of operator, instanceof, this operator is used to check an object that whether this is an object of specified class or not.

instanceof can also be used to determine whether an object of a class is inheriting property  from another class or not.

It can also check that an object is not an instanceof a class, the  logical not is used.

Example:

<?php

class A

{

var $var;

function disp()

{

echo "Inside the class";

}

}

$obj=new A;

var_dump($obj instanceof A);

?>

Output:

bool(true)

Example:

<?php

class A

{

var $var;

function disp()

{

echo "Inside the class";

}

}

$obj=new A;

var_dump (!($obj instanceof A));

?>

Output:

bool(false)

Advertisements

Advertisement

Posted on: March 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.