note 117463 deleted from function.is-a by cmb

From: Date: Thu, 03 Mar 2022 12:09:50 +0000
Subject: note 117463 deleted from function.is-a by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217677@lists.php.net to get a copy of this message
Note Submitter: portugal {at} jawira {dot} com ---- I just want to point out that you can replace "is_a()" function with the "instanceof" operator, BUT you must use a variable to pass the class name string. This will work: <?php $object = new \stdClass(); $class_name = '\stdClass'; var_dump(is_a($object, $class_name)); // bool(true) var_dump(is_a($object, '\stdClass')); // bool(true) var_dump($object instanceof $class_name); // bool(true) ?> While this don't: <?php $object = new \stdClass(); var_dump($object instanceof '\stdClass'); // Parse error: syntax error, unexpected ''\stdClass'' (T_CONSTANT_ENCAPSED_STRING) ?>

« previous php.notes (#217677) next »