3 pontos por smartbosslee 2020-07-16 | 3 comentários | Compartilhar no WhatsApp

// Antes

switch ($this->lexer->lookahead['type']) {

case Lexer::T_SELECT:

    $statement = $this->SelectStatement();

    break;

case Lexer::T_UPDATE:

    $statement = $this->UpdateStatement();

    break;

case Lexer::T_DELETE:

    $statement = $this->DeleteStatement();

    break;

default:

    $this->syntaxError('SELECT, UPDATE ou DELETE');

    break;

}

// Depois

$statement = match ($this->lexer->lookahead['type']) {

Lexer::T_SELECT => $this->SelectStatement(),

Lexer::T_UPDATE => $this->UpdateStatement(),

Lexer::T_DELETE => $this->DeleteStatement(),

default => $this->syntaxError('SELECT, UPDATE ou DELETE'),

};

3 comentários

 
kunggom 2020-07-17

No Java também entrou nas versões mais recentes um switch com funcionalidades aprimoradas. Acho que esse tipo de coisa é a tendência do momento.

https://pt.news.hada.io/topic?id=1130

 
xguru 2020-07-16

Novos recursos do PHP 8 https://pt.news.hada.io/topic?id=1438

Acho que isso não estava lá quando essa notícia foi publicada, mas o texto original desse outro link também foi atualizado e o Match foi adicionado.

 
smartbosslee 2020-07-16

Sim. A inclusão já está confirmada, mas dizem que o próprio Match ainda pode sofrer mais mudanças.

Obrigado pelo link.