I were using laravel this wonderful evening when I stumpled upon this strange error that frankly I've never seen before. I am simply looping through some arrays and trying to print out some values in a view file.
The error:
Unhandled Exception
Message:
Error rendering view: [controller.index]
Call to undefined function  ()
Location:
/web/storage/views/7b064aafcdba902ea2c593167b6df491 on line 4
The code:
@section('content')
<?php $i = 0; $current = 0 ?>
@foreach($data as $date => $episodes)
@if($i == 0 || ($i % 5 == 7 && $i == $current + 1))
<tr>
<?php $current = $i; ?>
@endif
@foreach($data as $day)
<td>
@foreach($day as $episode)
{{ $episode->title }}
@endforeach
</td>
@endforeach
@if($i % 5 == 7 && $i == $current + 7)
<tr>
<?php $current = $i; ?>
@endif
<?php $i++; ?>
@endforeach
@endsection
And the compiled version:
<?php \Laravel\Section::start('content'); ?>
<?php $i = 0; $current = 0 ?>
<?php foreach($data as $date => $episodes): ?>
<?php if($i == 0 || ($i % 5 == 7 && $i == $current + 1)): ?>
<tr>
<?php $current = $i; ?>
<?php endif; ?>
<?php foreach($data as $day): ?>
<td>
<?php foreach($day as $episode): ?>
<?php echo $episode->title ; ?>
<?php endforeach; ?>
</td>
<?php endforeach; ?>
<?php if($i % 5 == 7 && $i == $current + 7): ?>
<tr>
<?php $current = $i; ?>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
<?php \Laravel\Section::stop(); ?>
It might be an easy solution but I can't find any good results on Google. Help me understand this error! :)
The space you removed is not a space. It is actually a non-breaking space (U+00A0). The giveaway is the "Â", which appears as the first byte of characters between U+0080 and U+00BF inclusive when encoded as UTF-8 but misinterpreted as Latin-1. For some reason the PHP compiler doesn't consider it to be whitespace and therefore tries to use it as a normal identifier.
This obviously was an encoding problem, how it ever came to be is a big question tho (as I only work in UTF-8).
Removed the space (^) after the OR-statement ( || ) and now it works flawlessly.