PHP - Function is_a()


Advertisements


Syntax

is_a ( $object, $class_name )

Definition and Usage

Checks if the given object is of this class or has this class as one of its parents.

Parameters

ParameterDescription
objectRequired. The tested object
classRequired. The class name.

Return Value

Returns TRUE if the object is of this class or has this class as one of its parents, FALSE otherwise.

Example

Following is the usage of this function:

<?php
class WidgetFactory
{
  var $oink = 'moo';
}

// create a new object
$WF = new WidgetFactory();

if (is_a($WF, 'WidgetFactory')) {
  echo "yes, \$WF is still a WidgetFactory";
}
?> 

It will produce following result:

yes, $WF is still a WidgetFactory

php_function_reference.htm

Advertisements