Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blade "or" syntax not working with associative arrays #16593

Closed
antoniomadonna opened this issue Nov 29, 2016 · 5 comments
Closed

Blade "or" syntax not working with associative arrays #16593

antoniomadonna opened this issue Nov 29, 2016 · 5 comments

Comments

@antoniomadonna
Copy link

  • Laravel Version: 5.3.25
  • PHP Version: 5.6.4
  • Database Driver & Version:

Description:

The blade "or" construct has been broken by e8a9ed1, the regex does not match when using associative arrays.

Steps To Reproduce:

Use {{ $array['foo'] or 'bar' }} in any view and get "undefined index 'foo'".

Failing test:

$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\' !!}'));
@GrahamCampbell
Copy link
Member

You can just use:

{{ $array['foo'] ?? 'bar' }}

@fernandobandeira
Copy link
Contributor

@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...

@themsaid
Copy link
Member

the mentioned PR was reverted.

@GrahamCampbell
Copy link
Member

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.

@manan-jadhav
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants