Home Tutorial Php Phpbasics Tutorial PHP Instanceof Operator

 
 

PHP Instanceof Operator
Posted on: March 20, 2010 at 12:00 AM
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)

Advertisement

Related Tags for PHP Instanceof Operator:


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.

Posted on: March 20, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com