note 71562 added to language.operators.type

From: Date: Wed, 06 Dec 2006 04:34:41 +0000
Subject: note 71562 added to language.operators.type
Groups: php.notes 
Request: Send a blank email to php-notes+get-120327@lists.php.net to get a copy of this message
I can confirm what thisbizness at gmail dot com said just below in PHP 5.2, furthermore, people looking to use this as a "if $a is not instance of A" for error throwing purposes or other, just type it like this: <?php if( !$a instanceof A ) { throw new Exception( '$a is not instance of A.' ); } ?> This also works if $a is not an object, or not even set (you will get an E_NOTICE if it isn't set though). A note worth making is that if you are unsure of if class A is present when making this comparison, and you don't want to trigger the __autoload() magic method, scroll down for examples of how to get around this. I was unsure about it at first since most other operators have their own negative (like !=) or they are/can be used as function calls (like !is_a()) but it is this simple. Hope it helps someone. Until again! ---- Server IP: 129.16.214.50 Probable Submitter: 81.235.191.71 ---- Manual Page -- http://www.php.net/manual/en/language.operators.type.php Edit -- https://master.php.net/note/edit/71562 Del: integrated -- https://master.php.net/note/delete/71562/integrated Del: useless -- https://master.php.net/note/delete/71562/useless Del: bad code -- https://master.php.net/note/delete/71562/bad+code Del: spam -- https://master.php.net/note/delete/71562/spam Del: non-english -- https://master.php.net/note/delete/71562/non-english Del: in docs -- https://master.php.net/note/delete/71562/in+docs Del: other reasons-- https://master.php.net/note/delete/71562 Reject -- https://master.php.net/note/reject/71562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120327) next »