note 124515 added to language.types.iterable
| From: | j_jaberi.yahoo.com via php-notes | Date: | Tue, 17 Dec 2019 12:44:32 +0000 |
| Subject: | note 124515 added to language.types.iterable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213547@lists.php.net to get a copy of this message | ||
Just to note:
Though objects may (or may not) be Traversable, the can use in foreach because implicit conversion
to array
<?php
class Foo {
public $a = 1;
public $b = "Helo";
};
$bar = new Foo;
foreach($bar as $elm) {
echo $elm . ' ';
}
?>
prints 1 Hello
Even
<?php
$bar = new stdClass
foreach($bar as $elm) {
echo $elm . ' ';
}
?>
is correct.
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.168 (proxied: 46.224.142.231)
----
Manual Page -- http://php.net/manual/en/language.types.iterable.php
Edit -- https://master.php.net/note/edit/124515
Del: integrated -- https://master.php.net/note/delete/124515/integrated
Del: useless -- https://master.php.net/note/delete/124515/useless
Del: bad code -- https://master.php.net/note/delete/124515/bad+code
Del: spam -- https://master.php.net/note/delete/124515/spam
Del: non-english -- https://master.php.net/note/delete/124515/non-english
Del: in docs -- https://master.php.net/note/delete/124515/in+docs
Del: other reasons-- https://master.php.net/note/delete/124515
Reject -- https://master.php.net/note/reject/124515
Search -- https://master.php.net/manage/user-notes.php