downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Iterator> <定義済みのインターフェイス
[edit] Last updated: Fri, 25 May 2012

view this page in

Traversable インターフェイス

(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)

導入

そのクラスの中身が foreach を使用してたどれるかどうかを検出するインターフェイスです。

これは抽象インターフェイスであり、単体で実装することはできません。 IteratorAggregate あるいは Iterator を実装しなければなりません。

注意:

このインターフェイスを実装した内部クラス (組み込みクラス) は foreach で使用することができます。 IteratorAggregateIterator を実装する必要はありません。

注意:

これは内部エンジンのインターフェイスであり、PHP スクリプトないで実装することはできません。 そのかわりに IteratorAggregate あるいは Iterator を使用しなければなりません。

インターフェイス概要

Traversable {
}

このインターフェイスにはメソッドがありません。 traverse 可能なすべてのクラス用の基底インターフェイスとしてのみ存在しています。



add a note add a note User Contributed Notes Traversable
kevinpeno at gmail dot com 02-Aug-2010 10:06
While you cannot implement this interface, you can use it in your checks to determine if something is usable in for each. Here is what I use if I'm expecting something that must be iterable via foreach.

<?php
   
if( !is_array( $items ) && !$items instanceof Traversable )
       
//Throw exception here
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites