Skip to content

Commit

Permalink
Raise an error when the 'for' tag cannot iterate over a value.
Browse files Browse the repository at this point in the history
This makes debugging a bit easier, because otherwise there would only be
a PHP error about "Invalid argument supplied for foreach" without giving
any clues which value it could possibly be.
  • Loading branch information
vdboor committed Jul 21, 2011
1 parent ea7394a commit 8e83446
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions h2o/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ function __construct($argstring, $parser, $position) {
function render($context, $stream) {
$iteratable = $context->resolve($this->iteratable);

// Make debugging a bit easier
if( ! is_array( $iteratable ) && ! $iteratable instanceof Traversable ) {
$repr = (is_object( $iteratable ) ? '<class: ' . get_class( $iteratable ) . '>' : (string)$iteratable );
throw new InvalidArgumentException("The for tag cannot iterate over the value: " . $repr);
}

if ($this->reversed)
$iteratable = array_reverse($iteratable);

Expand Down

0 comments on commit 8e83446

Please sign in to comment.