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

search for in the

Iterator> <Interfaces predefinidas
[edit] Last updated: Fri, 25 May 2012

view this page in

La interfaz Traversable

(No hay información de versión disponible, podría estar únicamente en SVN)

Introducción

Interfaz para detectar si una clase es tranvesable mediante foreach.

Una interfaz abstracta básica no puede ser implementada por su cuenta. Sin embargo debe ser implementada con IteratorAggregate o Iterator.

Nota:

Las clases internas que implementan esta interfaz pueden ser usadas en una construcción foreach y no necesitan implementar IteratorAggregate o Iterator.

Nota:

Este es el motor interno de una interfaz que no puede ser implementada en códigos de PHP. Se debe emplear en su lugar tanto IteratorAggregate como Iterator.

Sinopsis de la Interfaz

Traversable {
}

Esta interfaz no tiene métodos, ya que su único propósito es servir de interfaz básica para todas las clases traversable.



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 | sitemap | contact | advertising | mirror sites