Framework: [5.7] Why was removed "or" in blade

Created on 11 Sep 2018  路  7Comments  路  Source: laravel/framework

  • Laravel Framework 5.7.2
  • PHP Version: 7.2.9

_Error or New Feature?_

I use code in blade:
{{ $article->title or ' ' }}

[5.6] -> framework/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php

public function compileEchoDefaults($value)
{
        return preg_replace('/^(?=\$)(.+?)(?:\s+or\s+)(.+?)$/si', 'isset($1) ? $1 : $2', $value);
}

From ver 5.7 code block was removed.

All 7 comments

Because you can use ?? in PHP7.
{{ $article->title ?? ' ' }}

OK, Now all the code requires an update.

Plus there are many edge cases with "or" that you don't have to deal with when using "??".

@dka-develop yes, but your app will be faster because this code will be executed on lower level.

@antonkomarev You Right!

but modifying the code is too cumbersome ..... T.T

@Yi-Frank Don't upgrade then.

Was this page helpful?
0 / 5 - 0 ratings