3 points par smartbosslee 2020-07-16 | 3 commentaires | Partager sur WhatsApp

// Avant

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 or DELETE');

    break;

}

// Après

$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 or DELETE'),

};

3 commentaires

 
kunggom 2020-07-17

En Java aussi, une instruction Switch aux fonctionnalités améliorées a été intégrée dans les versions récentes. On dirait que c’est la tendance du moment.

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

 
xguru 2020-07-16

Nouvelles fonctionnalités de PHP 8 https://fr.news.hada.io/topic?id=1438

Il me semble que ce n’était pas encore présent au moment de la publication de cette news, mais l’article original de ce côté a lui aussi été mis à jour avec les dernières informations et match y a été ajouté.

 
smartbosslee 2020-07-16

Oui. Son ajout est confirmé, mais il paraît que Match lui-même peut encore évoluer.

Merci pour le lien.