note 114519 deleted from class.traversable by cmb

From: Date: Mon, 24 Aug 2015 17:48:38 +0000
Subject: note 114519 deleted from class.traversable by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203443@lists.php.net to get a copy of this message
Note Submitter: mathdegiovani at gmail dot com ---- Note that instanceof Traversable does not work for stdclass objects, so if you are this check (as @kevinpeno) to decide whether you can iterate, it will fail for direct instances. In particular: <?php $obj = new stdclass(); $obj->prop = 'hello'; var_dump($obj instanceof Traversable); //outputs bool(false) ?> My own solution is to check whether the object also descends from stdclass, but that also fails to catch some objects that are iterable.

« previous php.notes (#203443) next »