The blade "or" construct has been broken by https://github.com/laravel/framework/commit/e8a9ed155fd10ac7b3595421055d1577fee246a0, the regex does not match when using associative arrays.
Use {{ $array['foo'] or 'bar' }} in any view and get "undefined index 'foo'".
$compiler = new Illuminate\View\Compilers\BladeCompiler($this->getFiles(), __DIR__);
$this->assertEquals('<?php echo isset($name[\'bar\']) ? $name[\'bar\'] : \'foo\'; ?>', $compiler->compileString('{!! $name[\'bar\'] or \'foo\' !!}'));
You can just use:
{{ $array['foo'] ?? 'bar' }}
@GrahamCampbell He can't since he's on PHP Version: 5.6.4... But yeah this is useless for people on PHP7, guess it'll be removed soon...
Should we revert that fix and apply it in a future release?
It fixes an edge case
{{$var['a or b']}}
This seems more important...
the mentioned PR was reverted.
I have an experimental idea for how to fix this for really reals. It will require significant work though. I'm going to attempt this when I have some free time summer 2017.
I've been trying to figure out the perfect regex. This is still buggy and needs to be fixed.
Lesson learnt : add as many test cases as possible.
Most helpful comment
I have an experimental idea for how to fix this for really reals. It will require significant work though. I'm going to attempt this when I have some free time summer 2017.