note 71398 deleted from language.operators.type by colder

From: Date: Sat, 24 Feb 2007 10:04:09 +0000
Subject: note 71398 deleted from language.operators.type by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123815@lists.php.net to get a copy of this message
Note Submitter: thisbizness at gmail dot com ---- *** w dot bogaerts at kratz dot nl said: instanceof only works with objects. So if you want to check if a variable is an object that implements a certain interface, you need two checks: is_object and instanceof. A fatal error occurs if instanceof is used with other data types. *** I don't exactly know what he meant by that because I was able to use instanceof just fine with other data types. <?php class A{ function __construct(){} } function test($variable) { echo ($variable instanceof A) ? "this is an instance of class A<br/>" : "this is not an object<br/>"; } $a = new A(); //object $b = array("a","b","c"); //array $c = "c"; //string test($a); test($b); test($c); test("d"); //string again ?> results: this is an instance of class A this is not an object this is not an object this is not an object

« previous php.notes (#123815) next »