I think the condition should be 
```
if (!isset($tag['_elem']) || $tag['_elem'] !== 'opentag')
```
beause if the variable isn't set there is a value differ to 'opentag'
The same problem exists in line 52.