note 114519 added to class.traversable

From: Date: Mon, 03 Mar 2014 13:41:49 +0000
Subject: note 114519 added to class.traversable
Groups: php.notes 
Request: Send a blank email to php-notes+get-198769@lists.php.net to get a copy of this message
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. ---- Server IP: 187.73.33.55 Probable Submitter: 177.106.10.158 ---- Manual Page -- http://php.net/manual/en/class.traversable.php Edit -- https://master.php.net/note/edit/114519 Del: integrated -- https://master.php.net/note/delete/114519/integrated Del: useless -- https://master.php.net/note/delete/114519/useless Del: bad code -- https://master.php.net/note/delete/114519/bad+code Del: spam -- https://master.php.net/note/delete/114519/spam Del: non-english -- https://master.php.net/note/delete/114519/non-english Del: in docs -- https://master.php.net/note/delete/114519/in+docs Del: other reasons-- https://master.php.net/note/delete/114519 Reject -- https://master.php.net/note/reject/114519 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198769) next »