fabpot/Twig — Issue #586: PHP Warning when using SplObjectStorage in templates
Author: jpb0104
Created: 2012-01-08 20:49:06+00:00
State: open

When using [SplObjectStorage](http://php.net/manual/en/class.splobjectstorage.php) in templates PHP issues a warning.

PHP Warning: SplObjectStorage::offsetExists() expects parameter 1 to be object, string given in [..]/vendor/twig/twig/lib/Twig/Template.php on line 330

I've narrowed it down to the `isset($object[$item])` https://github.com/fabpot/Twig/blob/master/lib/Twig/Template.php#L330

Controller

```php
$storage = new SplObjectStorage();

$obj = new stdClass();
$obj->name = 'one';
$storage->attach($obj);

$obj = new stdClass();
$obj->name = 'two';
$storage->attach($obj);

$twig->render('template.twig', array('storage' => $storage));
```

Template

```

{% for row in storage %}

{{ row.name }}

{% endfor %}

```