Improved exception message while trying to access an attribute from an empty array

Rebased #1439 in master and updated twig extension